Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PurgeCSS Configuration #2788

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions content/en/hugo-pipes/postprocess.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,23 @@ See the [configure build] documentation for details and options.
`postcss.config.js`

```js
const purgecss = require('@fullhuman/postcss-purgecss')({
content: [ './hugo_stats.json' ],
defaultExtractor: (content) => {
let els = JSON.parse(content).htmlElements;
return els.tags.concat(els.classes, els.ids);
}
});
const { purgeCSSPlugin } = require('@fullhuman/postcss-purgecss');

const purgecssConfig = {
content: ["./hugo_stats.json"],
defaultExtractor: (content) => {
let els = JSON.parse(content).htmlElements;
return els.tags.concat(els.classes, els.ids);
},
};

module.exports = {
plugins: [
...(process.env.HUGO_ENVIRONMENT === 'production' ? [ purgecss ] : [])
]
};
plugins: [
...(process.env.HUGO_ENVIRONMENT === 'production'
? [purgeCSSPlugin(purgecssConfig)]
: [])
]
};
```

Note that in the example above, the "CSS purge step" will only be applied to the production build. This means that you need to do something like this in your head template to build and include your CSS:
Expand Down