summaryrefslogtreecommitdiffstats
path: root/config/commonConfig.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-03-03 12:25:03 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-04-09 22:57:26 +0200
commit095bf64c99f57efe083540a50e658808a0a1c32b (patch)
tree18d3ffb1701250ca5ef3caa2073214b6b9aff6f1 /config/commonConfig.go
parent7791a804e2179667617b3b145b0fe7eba17627a1 (diff)
Collect HTML elements during the build to use in PurgeCSS etc.
The main use case for this is to use with resources.PostProcess and resources.PostCSS with purgecss. You would normally set it up to extract keywords from your templates, doing it from the full /public takes forever for bigger sites. Doing the template thing misses dynamically created class names etc., and it's hard/impossible to set up in when using themes. You can enable this in your site config: ```toml [build] writeStats = true ``` It will then write a `hugo_stats.json` file to the project root as part of the build. If you're only using this for the production build, you should consider putting it below `config/production`. You can then set it up with PostCSS like this: ```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: [ require('tailwindcss'), require('autoprefixer'), ...(process.env.HUGO_ENVIRONMENT === 'production' ? [ purgecss ] : []) ] }; ``` Fixes #6999
Diffstat (limited to 'config/commonConfig.go')
-rw-r--r--config/commonConfig.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/config/commonConfig.go b/config/commonConfig.go
index 17d5619bb..ba99260a5 100644
--- a/config/commonConfig.go
+++ b/config/commonConfig.go
@@ -29,11 +29,16 @@ import (
var DefaultBuild = Build{
UseResourceCacheWhen: "fallback",
+ WriteStats: false,
}
// Build holds some build related condfiguration.
type Build struct {
UseResourceCacheWhen string // never, fallback, always. Default is fallback
+
+ // When enabled, will collect and write a hugo_stats.json with some build
+ // related aggregated data (e.g. CSS class names).
+ WriteStats bool
}
func (b Build) UseResourceCache(err error) bool {