Installation
Setting up Tailwind CSS in a Phoenix project.
Start by creating a new Phoenix project if you don't have one set up already. You can follow their installation guide to get up and running.
mix phx.new myprojectcd myprojectAdd the Tailwind plugin to your dependencies and run mix deps.get to install it.
defp deps do [ # … {:tailwind, "~> 0.3", runtime: Mix.env() == :dev}, ]endIn your config/config.exs file you can set which version of Tailwind CSS you want to use and customize your asset paths.
config :tailwind, version: "4.0.0", myproject: [ args: ~w( --input=assets/css/app.css --output=priv/static/assets/app.css ), cd: Path.expand("..", __DIR__) ]Configure your assets.deploy alias to build your CSS on deployment.
defp aliases do [ # … "assets.deploy": [ "tailwind myproject --minify", "esbuild myproject --minify", "phx.digest" ] ]endAdd Tailwind to your list of watchers in your ./config/dev.exs file.
watchers: [ # Start the esbuild watcher by calling Esbuild.install_and_run(:default, args) esbuild: {Esbuild, :install_and_run, [:myproject, ~w(--sourcemap=inline --watch)]}, tailwind: {Tailwind, :install_and_run, [:myproject, ~w(--watch)]}]Run the install command to download the standalone Tailwind CLI.
mix tailwind.installAdd an @import to ./assets/css/app.css that imports Tailwind CSS.
@import "tailwindcss";Remove the CSS import from ./assets/js/app.js, as Tailwind is now handling this for you.
// Remove this line if you add your own CSS build pipeline (e.g postcss).import "../css/app.css"Run your build process with mix phx.server.
mix phx.serverStart using Tailwind’s utility classes to style your content.
<h1 class="text-3xl font-bold underline"> Hello world!</h1>Tailwind CSS 中文网(本网站)的目标是为中文开发者提供准确、及时的 Tailwind CSS 中文文档
Tailwind CSS 中文文档由本网站维护人员共同翻译,采用 MIT 开源协议发布
本网站与 tailwindcss.com 及 Tailwind Labs Inc. 并无从属关系
Tailwind 商标由 Tailwind Labs Inc. 所有
京ICP备15031610号-106