From 89048f4b40fb31722b071250c0f59593e0b1d350 Mon Sep 17 00:00:00 2001 From: yova Date: Mon, 8 Aug 2022 20:14:14 +0200 Subject: [PATCH] add to disable csspurging on production see http://notes.gugelfrei.de/#root/CJy29hue71WM/HmK2rsbse12W-4KEq --- postcss.config.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 postcss.config.js diff --git a/postcss.config.js b/postcss.config.js new file mode 100644 index 0000000..6811a54 --- /dev/null +++ b/postcss.config.js @@ -0,0 +1,38 @@ +const removeNewlines = (string) => string.replace(/\n$/g, ""); + +// See https://gohugo.io/hugo-pipes/postprocess/#css-purging-with-postcss +const purgecss = require("@fullhuman/postcss-purgecss")({ + content: [ + // + // TODO: Maybe use process.cwd() to get some heuristics of what + // is going on, i.e. which of the following cases we are in. + // + + // When this file is copied to the root of your Hugo site + "./hugo_stats.json", + // When your Hugo site does not have its own postcss.config.js + // and hence this file is used inside ./themes/hugo-product-launch + "../../hugo_stats.json", + // When building the exampleSite during development + "./exampleSite/hugo_stats.json", + ], + defaultExtractor: (content) => { + let els = JSON.parse(content).htmlElements; + // An HTML element-name may include a newline, e.g. + // Yo! + // Thus we remove those newlines. + return els.tags.concat(els.classes, els.ids).map(removeNewlines); + }, +}); + +module.exports = { + plugins: [ + require("postcss-import"), + require("tailwindcss"), + require("autoprefixer"), + // ...(process.env.HUGO_ENVIRONMENT === "production" ? [purgecss] : []), + ], +};