From b7ed108f907562960ed7bca8b4bfc1dd805fe306 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Sun, 26 Jan 2025 18:33:54 -0800 Subject: [PATCH] Improve js.Build example and presentation of options --- content/en/functions/js/Build.md | 32 +++++---- content/en/functions/js/_common/options.md | 75 ++++++++++++++-------- 2 files changed, 68 insertions(+), 39 deletions(-) diff --git a/content/en/functions/js/Build.md b/content/en/functions/js/Build.md index 56118213f..3e78e8e98 100644 --- a/content/en/functions/js/Build.md +++ b/content/en/functions/js/Build.md @@ -28,31 +28,37 @@ The `js.Build` function uses the [evanw/esbuild] package to: ```go-html-template {{ with resources.Get "js/main.js" }} - {{ if hugo.IsDevelopment }} - {{ with . | js.Build }} + {{ $opts := dict + "minify" hugo.IsProduction + "sourceMap" (cond hugo.IsProduction "" "external") + "targetPath" "js/main.js" + }} + {{ with . | js.Build $opts }} + {{ if hugo.IsProduction }} + {{ with . | fingerprint }} + + {{ end }} + {{ else }} {{ end }} - {{ else }} - {{ $opts := dict "minify" true }} - {{ with . | js.Build $opts | fingerprint }} - - {{ end }} {{ end }} {{ end }} ``` ## Options -targetPath -: (`string`) If not set, the source path will be used as the base target path. +###### targetPath + +(`string`) If not set, the source path will be used as the base target path. Note that the target path's extension may change if the target MIME type is different, e.g. when the source is TypeScript. -format -: (`string`) The output format. One of: `iife`, `cjs`, `esm`. Default is `iife`, a self-executing function, suitable for inclusion as a `