A Postbuild task that optimizes generated HTML/CSS files by removing unused CSS selectors. The task uses PurgeCSS library under the hood.
Enable the task in your gatsby-config.js
plugins: [
{
resolve: `gatsby-plugin-postbuild`,
options: {
purgecss: {
enabled: true
}
}
}
]
Type:
Boolean
Default:false
Sets a custom PurgeCSS extractor that allows CSS selectors to contain symbols (e.g TailwindCSS).
Type:
Array
Default:[]
CSS files to exclude from optimiztion.
Type:
Array
Default:[]
JavaScript files to ignore while purging CSS.
Type:
Array
Default:['app', 'polyfill']
Ignores all JavaScript files under the specified chunck names. You can find these at /public/webpack.stats.json
.
Type:
Boolean
Default:true
Write a text file under /public
with a list of rejected selectors for every file (useful for debugging).
The following options are passed to PurgeCSS while optimizing CSS. See PurgeCSS Options for more info.
Type:
Function
Default:PurgeCSS.defaultExtractor
A custom PurgeCSS extractor to be used instead of the default one.
Type:
(Array|Object)
Default:[]
Selectors that are safe to leave in the final CSS.
Type:
Array|Object
Default:[]
Selectors that are blocked from appearing in the final CSS.
Type:
Boolean
Default:false
Remove any unused @font-face
rules in your css.
Type:
Boolean
Default:false
Remove any unused @keyframes
rules in your css.
Type:
Boolean
Default:false
Remove any unused variables in your css.