Hello,
I have installed postCSS + @fullhuman/postcss-purgecss in my hugo site.
And I see different results in hugo_stats.json
when i use:
-
hugo --gc
locally -
netlify build
locally
I checked and the HTML source code is exactly the same with both commands (ie. the missing classes removed from hugo_stats.json
are present in the html)
Here is some example of difference and missing classes in generated hugo_stats.json
.
Strangely the web site behaviour seem not affected Any idea or explanation ?
"htmlElements": {
"tags": [
+ "!--",
- "0?\"-\":\"\",i=parseint(n=math.abs(+n||0).tofixed(c))+\"\",j=(j=i.length)",
"iframe",
+ "iframe\n",
"img",
+ "img\n",
- "results.length;i++){writer.tag(results[i],'');}}\u003c/script",
- "btn-main-tel-hero",
File : package.json
"dependencies": {
"@fullhuman/postcss-purgecss": "^2.3.0",
"autoprefixer": "^9.8.6",
"postcss-cli": "^7.1.1"
},
File : postcss.config.js
module.exports = {
plugins: {
'@fullhuman/postcss-purgecss': {
content: ['./**/*.html', './**/*.js', './hugo_stats.json'],
},
autoprefixer: {
overrideBrowserslist: [
"last 2 versions",
"Explorer >= 8",
]
},
}
};
partial
I use this code for all my requested css.
{{- $isProd := hugo.IsProduction -}}
{{- $css := resources.Get "css/themefisher-font/style.css"}}
<!-- Utilise PurgeCSS -->
{{- $css = $css | resources.PostCSS (dict "config" "./postcss.config.js") }}
{{- if $isProd }}
{{- $css = $css | minify | fingerprint "sha384" }}
{{- end }}
<link rel="preload" href="{{ $css.RelPermalink }}" {{ if $isProd }}integrity="{{ $css.Data.Integrity }}"{{ end }} as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link href="{{ $css.RelPermalink }}" {{ if $isProd }}integrity="{{ $css.Data.Integrity }}"{{ end }} rel="stylesheet" type="text/css"></noscript>
File : netlify.toml
[build]
publish = "public"
command = "hugo --minify"
[context.production.environment]
HUGO_VERSION = "0.74.3"
HUGO_ENV = "production"
RUBY_VERSION = "2.6.2"
HUGO_ENABLEGITINFO = "true"
TZ = "Europe/Zurich"
NODE_VERSION = "12.2.0"
[context.deploy-preview]
command = "hugo --buildFuture -b $DEPLOY_PRIME_URL"
[context.deploy-preview.environment]
HUGO_VERSION = "0.74.3"
RUBY_VERSION = "2.6.2"
HUGO_ENABLEGITINFO = "true"
TZ = "Europe/Zurich"
NODE_VERSION = "12.2.0"
[context.branch-deploy]
command = "hugo -b $DEPLOY_PRIME_URL"
[context.branch-deploy.environment]
HUGO_VERSION = "0.74.3"
RUBY_VERSION = "2.6.2"
HUGO_ENABLEGITINFO = "true"
TZ = "Europe/Zurich"
NODE_VERSION = "12.2.0"