Last active
July 15, 2022 17:54
-
-
Save jfreeze/e68cc6e7a5bc54d96e5d39a3dcceb303 to your computer and use it in GitHub Desktop.
TailwindCSS Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mix phx.new app_name | |
cd app_name | |
cd assets | |
npm install tailwindcss @tailwindcss/ui postcss-import postcss-loader --save-dev | |
npx tailwindcss init | |
npx tailwind init tailwindcss-full.js --full | |
# Change the app dir to your app dir! | |
# modify tailwind.config.js | |
purge: [ | |
"../lib/<app_name>/**/*.ex", | |
"../lib/<app_name>_web/**/*.ex", | |
"../lib/<app_name>_web/**/*.html.eex", | |
"../lib/<app_name>_web/**/*.html.leex", | |
"./js/**/*.js" | |
], | |
plugins: [require("@tailwindcss/ui")], | |
# add postcss.config.js | |
module.exports = { | |
plugins: [ | |
require("postcss-import"), | |
require('tailwindcss'), | |
require('autoprefixer'), | |
require('postcss-nested') | |
] | |
} | |
# modify deploy script in package.json | |
"scripts": { | |
"deploy": "NODE_ENV=production webpack --mode production", | |
... | |
}, | |
# add ‘postcss-loader’ to module/rules/use in webpack.config.js | |
{ | |
test: /\.[s]?css$/, | |
use: [ | |
MiniCssExtractPlugin.loader, | |
'css-loader', | |
'sass-loader', | |
'postcss-loader' | |
], | |
} | |
# mv app.scss to live_view.scss | |
remove @import "./phoenix.css"; | |
# create app.scss | |
/* purgecss start ignore */ | |
@import "tailwindcss/base"; | |
@import "tailwindcss/components"; | |
/* purgecss end ignore */ | |
@import "tailwindcss/utilities"; | |
@import "live_view.scss"; | |
cd .. | |
mix deps.get | |
#Test | |
cd assets | |
npm i | |
npm run deploy | |
./node_modules/webpack/bin/webpack.js --mode development | |
cd .. | |
mix phx.digest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have added some extra features to some of my projects where I use hero patterns. This is in the tailwind.config.js file.