I'm using purgecss to remove unnecessary css from my project.
purgecss --css static/css/*.chunk.css --content index.html static/js/*.chunk.js --output static/css/
But unfortunately it also removes some css classes that I need so referring the docs I tried to use the safelist option to make some exceptions like these
purgecss --safelist [modal] --css static/css/*.chunk.css --content index.html static/js/*.chunk.js --output static/css/
It gives long error ending with this
at U.evaluateRule (/usr/local/lib/node_modules/purgecss/lib/purgecss.js:1:6585)
at /usr/local/lib/node_modules/purgecss/lib/purgecss.js:1:9659
(node:10023) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 593)
Got it working using alternate approach i.e. using configuration file purgecss.config.js
.
module.exports = {
content: ['build/index.html', 'build/static/js/*.chunk.js'],
css: ['build/static/css/*.chunk.css'],
output: 'build/static/css/',
safelist: [/^modal-/]
}
In package.json
file
"scripts": {
"postbuild": "purgecss --config ./purgecss.config.js",
.....other scripts
},