Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JIT mode for Tailwind not working in localhost preview in Next JS

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!

like image 705
Steph Avatar asked Aug 17 '21 12:08

Steph


People also ask

How do you add a JIT in Tailwind?

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'.

Can I use Tailwind with next JS?

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.

Can Tailwind Cdn be used for production?

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.


Video Answer


5 Answers

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}"],
like image 36
Brhane Giday Avatar answered Oct 19 '22 15:10

Brhane Giday


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

like image 96
saidfurkandize Avatar answered Oct 19 '22 17:10

saidfurkandize


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.

like image 1
Nilupul Heshan Avatar answered Oct 19 '22 15:10

Nilupul Heshan


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.

like image 1
slimshady Avatar answered Oct 19 '22 17:10

slimshady


in Nuxtjs, I added:

@import url('tailwindcss/dist/tailwind.min.css');

in to file: ~/assets/css/tailwind.css

like image 1
Efrén Avatar answered Oct 19 '22 15:10

Efrén