Configuration
PurgeCSS has a list of options that allow you to customize its behavior. Customization can improve the performance and efficiency of PurgeCSS. You can create a configuration file with the following options.
Configuration file
The configuration file is a simple JavaScript file. By default, the JavaScript API will look for purgecss.config.js
.
You can then use PurgeCSS with the file:
Options
content
PurgeCSS also works with raw content. To do this, you need to pass an object with the raw
property instead of a filename. To work properly with custom extractors you need to pass the extension
property along with the raw content.
extractors
PurgeCSS can be adapted to suit your needs. If you notice a lot of unused CSS is not being removed, you might want to use a custom extractor.
whitelist
You can whitelist selectors to stop PurgeCSS from removing them from your CSS. This can be accomplished with the options whitelist
and whitelistPatterns
.
In the example, the selectors .random
, #yep
, button
will be left in the final CSS.
whitelistPatterns
You can whitelist selectors based on a regular expression with whitelistPatterns
.
In the example, selectors ending with red
such as .bg-red
will be left in the final CSS.
whitelistPatternsChildren
You can whitelist selectors based on a regular expression with whitelistPatternsChildren
. Contrary to whitelistPatterns
, it will also whitelist children of the selectors.
In the example, selectors such as red p
or .bg-red .child-of-bg
will be left in the final CSS.
keyframes (default: false)
If you are using a CSS animation library such as animate.css, you can remove unused keyframes by setting the keyframes
option to true
.
fontFace (default: false)
If there are any unused @font-face rules in your css, you can remove them by setting the fontFace
option to true
rejected (default: false)
It can sometimes be more practical to scan through the removed list to see if there's anything obviously wrong. If you want to do it, use the rejected
option.
Last updated