tailwindcss: Tailwind not work as exepted with Webpack with JIT

What version of Tailwind CSS are you using?

2.1.1

What version of Node.js are you using?

14

What browser are you using?

Chrome

What operating system are you using?

Mac os

Reproduction repository

https://github.com/jbty/html-starter-typscript-scss-tailwind

The tailwind classes which are already in my html are working but I cannot add new ones.

I don’t understand where this came from. If I desete JIT everythings work as exepted but hot reload with webpack dev server is so long.

Tailwind config:

const colors = require('tailwindcss/colors');

module.exports = {
  mode: 'jit',

  purge: ['./dist/*.html', './dist/*.js'],

  darkMode: false,

  theme: {
    screens: {
      print: { raw: 'print' },
      sm: '640px',
      // => @media (min-width: 640px) { ... }
      md: '768px',
      // => @media (min-width: 768px) { ... }
      lg: '1024px',
      // => @media (min-width: 1024px) { ... }
      xl: '1280px',
      // => @media (min-width: 1280px) { ... }
      '2xl': '1536px',
      // => @media (min-width: 1536px) { ... }
    },

    extend: {
      fontFamily: {},
      colors: {
        transparent: 'transparent',
        current: 'currentColor',
        black: colors.black,
        white: colors.white,
        gray: colors.trueGray,
        indigo: colors.indigo,
        red: colors.rose,
        yellow: colors.amber,
      },
      fontSize: {},
    },
  },

  variants: {
    extend: {},
  },

  plugins: [],
};

Postcss config:

module.exports = {
  plugins: [require('autoprefixer'), require('@tailwindcss/jit')],
};

Webpack config:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
  entry: './src/app.ts',
  target: 'web',
  cache: true,

  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].[fullhash:8].js',
    sourceMapFilename: '[name].[fullhash:8].map',
    chunkFilename: '[id].[fullhash:8].js',
    clean: true,
  },

  module: {
    rules: [
      {
        test: /\.(sa|sc|c)ss$/,
        use: [
          {
            loader: 'style-loader',
          },
          {
            loader: 'css-loader',
          },
          {
            loader: 'postcss-loader',
          },
          'sass-loader',
        ],
      },
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
      {
        test: /\.(jpe?g|png|gif|svg)$/i,
        loader: 'file-loader',
        options: {
          name: '[name].[hash].[ext]',
          outputPath: 'assets/images',
          esModule: false,
        },
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/i,
        loader: 'file-loader',
        options: {
          outputPath: 'assets/fonts',
        },
      },
    ],
  },

  resolve: {
    extensions: ['.ts', '.js'],
  },

  plugins: [
    new HtmlWebpackPlugin({
      template: 'src/index.html',
      title: 'Webpack Starter',
      description: 'Webpack Starter',
    }),
    new CopyPlugin({
      patterns: [{ from: 'src/public' }],
    }),
  ],

 devServer: {
    contentBase: path.resolve(__dirname, 'dist'),
    watchContentBase: true,
    writeToDisk: true,
    hot: true,
  },
};

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

I should also mention that using tailwind in jit mode, compiltion happens twice (two round). I do not know anybody else noticed this problem. project: rollup + solidjs + tailwindcss

Had the same issue, Fixed by adding TAILWIND_MODE=watch as @nauvalazhar said. More specifically (for windows support) by: yarn add cross-env --dev and replacing craco start with cross-env TAILWIND_MODE=watch craco start in the package.json start script.

I also faced the same problem. I solve the problem by adding TAILWIND_MODE=watch.

Apologies @samadadi, I incorrectly thought this was your issue all this time. It didn’t notice that it was @jbty who had the original issue. All my comments were about his issue and it looks like his is solved.

Regarding your first issue, I don’t have any specific advice because I have not got much rollup experience. It might be related to Rollup somehow, but I can’t say for certain.

Is your second issue only happening in development mode? If so, I’m not sure that is a bug and it might be by just how it works. There is no real downside, right? It’s just an idiosyncrasy of JIT in dev mode. I would expect you get the correct, optimized CSS when you do your production build and the old class names are no longer present in your codebase.

I’d probably suggest you create a couple new issues in this repo with your specific details to get some guidance on both double compiles and on the removal of unused classes at dev time. Mostly because, since @jbty’s original issue is resolved, this might get closed.

Sorry I wasn’t clear. The problem is your postcss config. Keep mode: ‘jit’. Remove require(‘@tailwindcss/jit’). Add require(‘tailwindcss’).

require(‘@tailwindcss/jit’) was the old way before 2.1. It’s built in now and that special package is no longer needed. Remove it.

Thanks it’s work for me

Sorry I wasn’t clear. The problem is your postcss config. Keep mode: ‘jit’. Remove require(‘@tailwindcss/jit’). Add require(‘tailwindcss’).

require(‘@tailwindcss/jit’) was the old way before 2.1. It’s built in now and that special package is no longer needed. Remove it.

As of Tailwind 2.1, you should not use '@tailwindcss/jit' in your postcss config. Just use plain 'tailwindcss'. Your double compilation is probably because you are still using the separate jit package and are also setting mode: 'jit' in the tailwind config. I’m not sure what other problems that configuration could cause either.