Purgecss
Search…
JavaScript API
Start by installing PurgeCSS as a dev dependency.
1
npm i -D purgecss
Copied!
You can now use PurgeCSS inside a JavaScript file.
In the following examples, the options passed to PurgeCSS are the same as the ones here. The result purgecssResult is an array of an object containing the name of the files with the purged CSS.

ES6 with import

1
import Purgecss from 'purgecss'
2
const purgeCss = new Purgecss({
3
content: ['**/*.html'],
4
css: ['**/*.css']
5
})
6
const purgecssResult = purgecss.purge()
Copied!
The format of purgecssResult is
1
[
2
{
3
file: 'main.css',
4
css: '/* purged css for main.css */'
5
},
6
{
7
file: 'animate.css',
8
css: '/* purged css for animate.css */'
9
}
10
]
Copied!

ES5 with require

1
var Purgecss = require('purgecss')
2
var purgecss = new Purgecss({
3
content: ['**/*.html'],
4
css: ['**/*.css']
5
})
6
var purgecssResult = purgecss.purge()
Copied!
Last modified 2yr ago