Now that Tailwind CSS 1.4 is out it's a great time to upgrade your old, tired app. Okay, maybe your app already had version 1.3, but if not, the latest two versions (1.3 and 1.4) bring some amazing improvements. Most notable are the new space between utilities and built in PurgeCSS support.
Upgrading is easy! Run npm install
(pro tip: npm i
is a shortcut). You might need to double check your package.json
file if that doesn't work for you. Make sure your version constraint allows updating to 1.4+ -- mine looks like this:
1"tailwindcss": "^1.0",
1"tailwindcss": "^1.0",
So you've got the upgrade, but let's talk about how to use a snazzy new feature -- built in PurgeCSS support. If you're currently using the PurgeCSS Wrapper for Laravel Mix to add purgecss, we can remove it. Delete the laravel-mix-purgecss
line from your package.json
and run npm i
once again.
Open up your tailwind.config.js
file (you are using a config file, aren't you?)... add the new purge
property. Your config file might look like this:
1let defaultConfig = require('tailwindcss/defaultConfig')23module.exports = {4 // This is the new section5 purge: [6 // Your options may vary7 'app/**/*.php',8 'resources/**/*.less',9 'resources/**/*.js',10 'resources/**/*.php',11 ],1213 theme: {14 // ...15 },16}
1let defaultConfig = require('tailwindcss/defaultConfig')23module.exports = {4 // This is the new section5 purge: [6 // Your options may vary7 'app/**/*.php',8 'resources/**/*.less',9 'resources/**/*.js',10 'resources/**/*.php',11 ],1213 theme: {14 // ...15 },16}
You can pass any of the PurgeCSS options you were using with the laravel-mix-purgecss plugin to this too, it just requires a slightly different syntax:
1purge: {2 content: [3 // an array of files to look for classes in4 ],5 options: {6 // options to be passed directly to PurgeCSS7 }8}
1purge: {2 content: [3 // an array of files to look for classes in4 ],5 options: {6 // options to be passed directly to PurgeCSS7 }8}
Take a look at your webpack.mix.js
file. You should have a chunk like the following:
1.purgeCss({2 // your config options here3})
1.purgeCss({2 // your config options here3})
Pass those same options to the new purge
config in your Tailwind config file. Then you can remove them from your webpack config! Note that if you were using the default version of the laravel-mix-purgecss plugin you will need to be explicit about the files you want to search for classes to keep, as tailwind's new purge
option doesn't look for any files or directories by default.
For more information, check out the Tailwind docs on Controlling File Size.
Make sure to test that your setup is working by running npm run prod
. ✌️