Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Build Tailwind Not Including all classes

So I'm making an App with React 17, tailwind and craco and its works find in dev but when i build with craco, tailwind don't include classes as h-36, h-44, col-span-1...

That's my tailwind.config.js

module.exports = {
  purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
}
like image 889
David Dionis Avatar asked Oct 24 '25 09:10

David Dionis


2 Answers

There are some things that you should check:

  1. Make sure that you put the tailwind classes in className attribute instead of class attribute

  2. Do not use string concatenation to create class names. So, instead of writing <div class="text-{{ error ? 'red' : 'green' }}-600"></div>, write <div class="{{ error ? 'text-red-600' : 'text-green-600' }}"></div>

  3. Make sure that all your files are included in the purge command. Since you only specify './src/**/*.{js,jsx,ts,tsx}', this meant that tailwind will only scan what class should not be purged on those files with those extensions. This means that if you use tailwind classes in html files, tailwind will not scan those files. Also the same case if you somehow have files outside of ./src.

like image 115
CrystallizedSyrup Avatar answered Oct 26 '25 22:10

CrystallizedSyrup


For me, I had to ensure that I was including all of the file types in my purge array within tailwind.config.js. Hope this helps someone - mine was missing the .vue files.

My Laravel tailwind purge array now looks like:

purge: [
    './vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
    './vendor/laravel/jetstream/**/*.blade.php',
    './storage/framework/views/*.php',
    './resources/views/**/*.blade.php',
    './resources/js/**/*.vue',
],
like image 36
Jonathan Bird Avatar answered Oct 26 '25 23:10

Jonathan Bird