I'm building a Next JS website and running Tailwind with JIT. This is my tailwind.config.js:
module.exports = {
mode: "jit",
purge: ["./pages/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {},
extend: {},
plugins: [],
};
Problem is that every time I write new code I have to restart my server and run 'npm run dev' because it's not updating my CSS on http://localhost:3000/.
I also get a warning when I run my server:
warn - You have enabled the JIT engine which is currently in preview.
warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
Any ideas what might be causing this? Thanks!
It's pretty easy to enable the JIT compiler. All you have to do is update your tailwind. config. js file by adding the mode property which should have a value of 'jit'.
The quickest way to start using Tailwind CSS in your Next. js project is to use the Next. js + Tailwind CSS Example. This will automatically configure your Tailwind setup based on the official Next.
Use the Play CDN to try Tailwind right in the browser without any build step. The Play CDN is designed for development purposes only, and is not the best choice for production.
Since JIT mode generates your CSS on-demand by scanning your template files, it’s crucial that you configure the purge option in your tailwind.config.js file with all of your template paths, otherwise, your CSS will be empty. replace your purge entry with the following:
purge: ["./public/**/*.html", "./src/**/*.{js,jsx,ts,tsx,vue}"],
Check out this https://tailwindcss.com/docs/just-in-time-mode#styles-don-t-update-when-saving-content-files
You can also add TAILWIND_MODE=watch
to your .env file.
I hope it's work because when i delete this, i am also facing same error.
And this warning is fine. It just a message
I had the same issue,
After removing all inline tailwind classes and put them in CSS files with @apply
it gets to work well.
Maybe tailwind compiles CSS before Next server renders components.
fixed this, just edit the 'purge' property in your tailwind.config.js file a little by adding the correct path like this './public//*.html', './src//*.{js,jsx,ts,tsx,vue}',
and you're good to go.
in Nuxtjs, I added:
@import url('tailwindcss/dist/tailwind.min.css');
in to file: ~/assets/css/tailwind.css
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With