hugo/config
Bjørn Erik Pedersen 095bf64c99
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
2020-04-09 22:57:26 +02:00
..
privacy tests: Convert from testify to quicktest 2019-08-12 13:26:32 +02:00
services tests: Convert from testify to quicktest 2019-08-12 13:26:32 +02:00
commonConfig.go Collect HTML elements during the build to use in PurgeCSS etc. 2020-04-09 22:57:26 +02:00
commonConfig_test.go Add HTTP header support for the dev server 2020-03-08 19:57:30 +01:00
configLoader.go Add Hugo Modules 2019-07-24 09:35:53 +02:00
configLoader_test.go tests: Convert from testify to quicktest 2019-08-12 13:26:32 +02:00
configProvider.go Introduce a tree map for all content 2020-02-18 09:49:42 +01:00
configProvider_test.go tests: Convert from testify to quicktest 2019-08-12 13:26:32 +02:00
env.go Add Hugo Modules 2019-07-24 09:35:53 +02:00
env_test.go tests: Convert from testify to quicktest 2019-08-12 13:26:32 +02:00