Purge Extra Tailwind Classes From Your App
Tuesday, December 1, 2020
Purge Extra Tailwind Classes From Your App
When you use Tailwind, you'll get all the styles it has by default. But you're likely not using all those styles. It's best if you only ship the needed CSS to your user, right?
Tailwind makes this easy with the purge
array in the tailwind.config.js
file. Just put in a list of paths to match for style purging, and webpack will do the rest. The only thing you'll need to remember is that when you run your app's build command, you need to set the NODE_ENV
to production. So for an angular app:
NODE_ENV=production ng build --prod my-app
I just enabled this and the styles for my app went from 3.53mb to 10kb. That's .2% of the original size!
Instructions
checkmark-circle
NODE_ENV=production ng build --prod my-app
Code Examples
tailwind.config.js
purge: [
'./apps/ngneat-dag-demo/src/**/*.html',
'./apps/ngneat-dag-demo/**/*.ts',
'./libs/**/*.html',
'./libs/**/*.ts',
],
Have a question or comment?