In my create-react-app application I'm using Tailiwnd CSS for styling. Unfortunately after running npm run build the css file size is around 1,4mb which is way too big. After looking inside that build file I can see that all unused class are still there,
Here are the scripts from package.json:
"scripts": {
"build:css": "postcss src/tailwind.css -o src/tailwind.generated.css",
"watch:css": "postcss src/tailwind.css -o src/tailwind.generated.css --watch",
"env:dev": "cross-env NODE_ENV=development",
"env:prod": "cross-env NODE_ENV=production",
"react-scripts:start": "sleep 5 && react-scripts start",
"react-scripts:build": "react-scripts build",
"start": "run-p env:dev watch:css react-scripts:start",
"build": "run-s env:prod build:css react-scripts:build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
To minify the build css file size I'm using Purge CSS with following postcss.config.js:
const purgecss = require('@fullhuman/postcss-purgecss')({
content: ['./public/**/*.html'],
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
});
module.exports = {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
// Purge and minify CSS only production builds only
...(process.env.NODE_ENV === 'production'
? [purgecss, require('cssnano')]
: [])
]
};
Here is the tailiwnd.config.js:
module.exports = {
purge: [
'./src/**/*.html',
'./src/**/*.vue',
'./src/**/*.jsx',
'./src/**/*.js'
],
theme: {
extend: {
height: {
'72': '18rem',
'80': '20rem',
'88': '22rem',
'96': '24rem',
'104': '26rem'
},
fontFamily: {
display: 'Raleway, sans-serif'
}
}
},
variants: {},
plugins: []
};
All of my javascript files are inside ./src folder. Do you have maybe any idea why CSS build file is still that big? I'm using only couple of the classes from Tailiwnd and the app itself is very simple and small,
Thanks!