From 085271a6a37a4c514b8aa6b083d452b110ba5ca2 Mon Sep 17 00:00:00 2001 From: nauichan <85791020+lauichan@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:16:44 +0900 Subject: [PATCH 1/3] Update PurgeCSS Configuration --- content/en/hugo-pipes/postprocess.md | 30 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/content/en/hugo-pipes/postprocess.md b/content/en/hugo-pipes/postprocess.md index 57c71e8ab9..f2c60a5cb8 100755 --- a/content/en/hugo-pipes/postprocess.md +++ b/content/en/hugo-pipes/postprocess.md @@ -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); - } -}); - -module.exports = { - plugins: [ - ...(process.env.HUGO_ENVIRONMENT === 'production' ? [ purgecss ] : []) - ] - }; +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 = (env) => { + return { + plugins: [ + ...(env === "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: From 83a567d10d906b9224e38767e77c49b96282a5be Mon Sep 17 00:00:00 2001 From: nauichan <85791020+lauichan@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:27:58 +0900 Subject: [PATCH 2/3] Update postprocess.md environment check for hugo --- content/en/hugo-pipes/postprocess.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/content/en/hugo-pipes/postprocess.md b/content/en/hugo-pipes/postprocess.md index f2c60a5cb8..5098714efd 100755 --- a/content/en/hugo-pipes/postprocess.md +++ b/content/en/hugo-pipes/postprocess.md @@ -61,12 +61,12 @@ const purgecssConfig = { }, }; -module.exports = (env) => { - return { - plugins: [ - ...(env === "production" ? [purgeCSSPlugin(purgecssConfig)] : []), - ], - }; +module.exports = { + plugins: [ + ...(process.env.NODE_ENV === 'production' + ? [purgeCSSPlugin(purgecssConfig)] + : []) + ] }; ``` From ed240c863b09efad1ee8b34447be77cd975dbe3a Mon Sep 17 00:00:00 2001 From: nauichan <85791020+lauichan@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:40:38 +0900 Subject: [PATCH 3/3] NODE_ENV -> HUGO_ENVIRONMENT --- content/en/hugo-pipes/postprocess.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/en/hugo-pipes/postprocess.md b/content/en/hugo-pipes/postprocess.md index 5098714efd..cb4a1c8f1f 100755 --- a/content/en/hugo-pipes/postprocess.md +++ b/content/en/hugo-pipes/postprocess.md @@ -63,7 +63,7 @@ const purgecssConfig = { module.exports = { plugins: [ - ...(process.env.NODE_ENV === 'production' + ...(process.env.HUGO_ENVIRONMENT === 'production' ? [purgeCSSPlugin(purgecssConfig)] : []) ]