feat(link.html): add support for deferred loading and ES modules for main style and js files

This commit is contained in:
Sped0n
2023-11-03 14:27:42 +08:00
parent c068133cd1
commit 6a0e06b050

View File

@@ -9,15 +9,9 @@
{{/* main style */}}
{{- if site.Params.bundled -}}
<link
rel="stylesheet"
as="style"
onload="this.onload=null;this.rel='stylesheet'"
href="/bundled/css/style.min.css"
/>
<noscript><link rel="stylesheet" href="/bundled/css/style.min.css" /></noscript>
{{- $style := dict "Link" "/bundled/css/style.min.css" "Defer" true -}}
{{- partial "plugin/style.html" $style -}}
{{- else -}}
{{- $style := dict "Source" "scss/style.scss" "Fingerprint" $fingerprint -}}
{{- $style := dict "Source" "scss/style.scss" "Fingerprint" $fingerprint -}}
{{- $options := dict "targetPath" "css/style.css" "enableSourceMap" true "includePaths" (slice "node_modules") -}}
{{- $style = dict "Context" . "ToCSS" $options "Minify" hugo.IsProduction "Defer" true | merge $style -}}
@@ -25,7 +19,8 @@
{{- end -}}
{{/* main js */}}
<script type="module" src="/bundled/js/main.js" defer></script>
{{- $script := dict "Link" "/bundled/js/main.js" "Defer" true "Esm" true -}}
{{- partial "plugin/script.html" $script -}}
{{/* fonts */}}
<link rel="preload" href="/lib/fonts/NotoSans-Regular.woff2" as="font" crossorigin />