Skip to content

Instantly share code, notes, and snippets.

@jmooring
Created September 2, 2023 02:58
Show Gist options
  • Save jmooring/95306dc46b8cfd1d69d82118a8e4ee64 to your computer and use it in GitHub Desktop.
Save jmooring/95306dc46b8cfd1d69d82118a8e4ee64 to your computer and use it in GitHub Desktop.
Hugo - Transpile, tree shake, and minify JavaScript
{{ with resources.Get "js/main.js" }}
{{ if eq hugo.Environment "development" }}
{{ with . | js.Build }}
<script src="{{ .RelPermalink }}"></script>
{{ end }}
{{ else }}
{{ $opts := dict "minify" true }}
{{ with . | js.Build $opts | fingerprint }}
<script src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script>
{{ end }}
{{ end }}
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment