- Navigate to the
assets
dircd assets/
- Install fortawesome, esbuild esbuild-sass-plugins, chokidar (used for watching), tailwind, postcss, and the phoenix deps
npm install --save-dev fs path chokidar esbuild esbuild-sass-plugin postcss autoprefixer tailwindcss @fortawesome/fontawesome-free ../deps/phoenix ../deps/phoenix_html ../deps/phoenix_live_view
- Create a
build.js
file with the contents of thebuild.js
file in this gist (I prefer to put this inside of ascripts
directory inside ofassets
. If you leave it at the root, you will need to update thebuild.js
file relative paths) - Create the tailwind.config.js in
assets
root with the contents of thetailwind.config.js
file in this gist - Rename
app.css
toapp.scss
- At the top of the
app.scss
file, add the following (also in this gist asapp.scss
)
$fa-font-path: "@fortawesome/fontawesome-free/webfonts/";
@import "@fortawesome/fontawesome-free/scss/fontawesome";
@import "@fortawesome/fontawesome-free/scss/regular";
@import "@fortawesome/fontawesome-free/scss/solid";
@import "@fortawesome/fontawesome-free/scss/brands";
@import "@fortawesome/fontawesome-free/scss/v4-shims";
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
- Update the phoenix configs to use the script file instead of esbuild cli.
config/config.exs
config :esbuild,
version: "0.12.18",
node: [
"build.js",
cd: Path.expand("../assets/scripts/", __DIR__),
env: %{"ESBUILD_LOG_LEVEL" => "silent", "ESBUILD_WATCH" => "1", "NODE_ENV" => "development"}
]
config/dev.exs
watchers: [
node: [
"build.js",
cd: Path.expand("../assets/scripts/", __DIR__),
env: %{"ESBUILD_LOG_LEVEL" => "silent", "ESBUILD_WATCH" => "1", "NODE_ENV" => "development"}
]
mix.exs
defp aliases do
[
setup: ["deps.get"],
"assets.deploy": [
"cmd --cd assets NODE_ENV=production node scripts/build.js",
"phx.digest"
]
]
end
- Update
assets/js/app.js
for the newscss
file extensionimport ../css/app.scss
- Use the icons in your html
<i class="fas fa-{ICON}></i>
- Use tailwind in your eex/leex/heex/html templates or inside of css:
<main class="container">content</main>
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Button
</button>
main {
@apply container;
}
.btn-blue {
@apply bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded;
}
@hammsvietro I didn't notice any difference after adding this change - the
css/app.scss
is still built because of it's imported in theapp.js
.Can you please eplain why is this needed?