diff --git a/package.json b/package.json index e8fdda84a..f383a9189 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "scripts": { "start": "npm run serve", - "build": "hugo --cleanDestinationDir --printPathWarnings --printUnusedTemplates", + "build": "hugo --cleanDestinationDir --minify --printPathWarnings --printUnusedTemplates", "serve": "hugo server --port 4000 --disableFastRender --noHTTPCache --renderToMemory --printPathWarnings --printUnusedTemplates", "serve-only": "npx sirv-cli _site --port 4000", "test": "npm-run-all build --parallel --continue-on-error --aggregate-output test-*", diff --git a/src/layouts/partials/scripts.html b/src/layouts/partials/scripts.html index 624da97e1..e134eab5a 100644 --- a/src/layouts/partials/scripts.html +++ b/src/layouts/partials/scripts.html @@ -5,14 +5,21 @@ {{- end -}} {{- $bootstrapJs := resources.Get "/js/vendor/bootstrap.bundle.min.js" | fingerprint | resources.Copy "/assets/js/vendor/bootstrap.bundle.min.js" -}} - + -{{- $application := resources.Get "js/application.js" | js.Build $esbuildOptions | fingerprint | resources.Copy "/assets/js/application.js" -}} -{{- $lazyload := resources.Get "js/lazyload.js" | js.Build $esbuildOptions | fingerprint | resources.Copy "/assets/js/lazyload.js" -}} +{{- $scripts := slice "js/application.js" "js/lazyload.js" -}} +{{- range $script := $scripts -}} +{{- $_script := resources.Get $script | js.Build $esbuildOptions | fingerprint -}} - - +{{- if hugo.IsProduction -}} + {{- $_script = $_script | resources.Minify -}} +{{- end -}} + +{{- $_script = $_script | resources.Copy (path.Join "/assets" $script) -}} + + +{{- end -}} {{ range .Page.Params.extra_js -}} - + {{- end -}} diff --git a/src/layouts/partials/stylesheet.html b/src/layouts/partials/stylesheet.html index fbfc9f35f..1f8ff3720 100644 --- a/src/layouts/partials/stylesheet.html +++ b/src/layouts/partials/stylesheet.html @@ -5,6 +5,10 @@ {{- $sassOptions = merge $sassOptions (dict "outputStyle" "compressed") -}} {{- end -}} -{{- $style := resources.Get "scss/style.scss" | toCSS $sassOptions | postCSS $postcssOptions | fingerprint -}} +{{- $style := resources.Get "scss/style.scss" | toCSS $sassOptions | postCSS $postcssOptions -}} +{{- if hugo.IsProduction -}} + {{- $style = $style | resources.Minify -}} +{{- end -}} +{{- $style = $style | fingerprint -}} - +