Skip to content

Instantly share code, notes, and snippets.

@belgoros
Created October 10, 2022 13:10
Show Gist options
  • Save belgoros/92f1d5d4b8d2cfaf4e4f8770a0d80a18 to your computer and use it in GitHub Desktop.
Save belgoros/92f1d5d4b8d2cfaf4e4f8770a0d80a18 to your computer and use it in GitHub Desktop.
Set up Tailwind in a Phoenix application

Set up Tailwind CSS in a Phoenix application

  • add tailwind dependency to the mix.exs file: {:tailwind, "~> 0.16", runtime: Mix.env() == :dev}
  • Configure tailwind in config.exs, where it will read, and where it will output the data:
config :tailwind, version: "3.1.4", default: [
  args: ~w(
    --config=tailwind.config.js
    --input=css/app.css
    --output=../priv/static/assets/app.css
  ),
  cd: Path.expand("../assets", __DIR__)
]
  • Include the Deploy Script in mix.exs:
 defp aliases do
    [
      setup: ["deps.get"],
      "assets.deploy": ["tailwind default --minify", "esbuild default --minify", "phx.digest"]
    ]
  end
  • Install Tailwind with mix tailwind.install
  • Include the import modules in: ./assets/tailwind.config.js:
module.exports = {
  content: [
    './js/**/*.js',
    '../lib/*_web.ex',
    '../lib/*_web/**/*.*ex',
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
  • Include Tailwind's Core components in app.css:
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
...
  • remove previously generated phoenix.css file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment