When you are building a website, chances are that you are using a css framework like Bootstrap, Materializecss, Foundation, etc... But you will only use a small set of the framework and a lot of unused css styles will be included.
This is where PurgeCSS comes into play. PurgeCSS analyzes your content and your css files. Then it matches the selectors used in your files with the one in your content files. It removes unused selectors from your css, resulting in smaller css files.
You can find the PurgeCSS documentation on this website.
- Configuration
- CLI
- Javascript API
- Webpack plugin
- Gulp plugin
- Grunt plugin
- Rollup plugin
- Whitelisting
- Extractors
- Comparison
- Guides
npm i --save-dev purgecss
import Purgecss from 'purgecss'
const purgeCss = new Purgecss({
content: ['**/*.html'],
css: ['**/*.css']
})
const result = purgeCss.purge()
With a custom extractor:
import Purgecss from 'purgecss'
import purgeHtml from 'purgecss-from-html'
const purgeCss = new Purgecss({
content: ['**/*.html'],
css: ['**/*.css'],
extractors: [
{
extractor: purgeHtml,
extensions: ['html']
}
]
})
const result = purgeCss.purge()
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
PurgeCSS use SemVer for versioning.
PurgeCSS was originally thought as the v2 of purifycss. And because of it, it is
greatly inspired by it.
Some of the plugins such as purgecss-webpack-plugin are based on the purifycss plugin.
Below is the list of the purifycss repositories:
This project is licensed under the MIT License - see the LICENSE file for details.
The extractors needs to be defined from the more specific to the less specific.
Meaning that you need to define js
extractor after ejs
. So the js
extractor will not be selected for ejs files.
You can specified extensions like
.es.js
.