This answer is outdated. Newer versions of tailwind support JIT as default
Giorgio Tempesta's steps are correct but need to improve for best performance.
Follow below steps for live output to your output css file with JIT mode (Just in time). So when you working on your project you don't need to compile source css file manually. Also JIT mode brings dynamic class implementations like bg-[#abcaaa]
in your package.json file add these to scripts
area like
"scripts": {
"watch-tailwind": "npx tailwindcss -i source.css -o output.css -w --minify",
"build-tailwind": "npx tailwindcss -i source.css -o output.css --minify"
},
Flag meanings;
-i:input file
-o:output file
-w:watch changes
--minify: minify output css file
- source.css is your main ang gigantic source css file.
- output.css is your just in time compiled and minified css file.
Also your tailwind.config.css
file should look basically like this
module.exports = {
mode: "jit", <------------ add this for immediate compile
purge: ["./src/**/*.html", "./src/**/*.js"], <--- give here your source files
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
};
After saved this settings on your package.json run;
npm run watch-tailwind
When you run this npm script, tailwind starts to listen changes in your project and output ONLY necessary css declarations to your output.css
It's huge difference. Before you doing above steps your css file is nearly 18MB
After compiling it's nearly 20-30KB
See JIT mode in action: https://tailwindcss.com/docs/just-in-time-mode
This is new era for tailwind.
Note: JIT mode available on v2.1+