diff options
Diffstat (limited to 'docs/content/en/functions/js/Build.md')
-rw-r--r-- | docs/content/en/functions/js/Build.md | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/docs/content/en/functions/js/Build.md b/docs/content/en/functions/js/Build.md index 9bdc2454a..1bec6b16f 100644 --- a/docs/content/en/functions/js/Build.md +++ b/docs/content/en/functions/js/Build.md @@ -3,17 +3,11 @@ title: js.Build description: Bundle, transpile, tree shake, and minify JavaScript resources. categories: [] keywords: [] -action: - aliases: [] - related: - - functions/js/Batch - - functions/js/Babel - - functions/resources/Fingerprint - - functions/resources/Minify - returnType: resource.Resource - signatures: ['js.Build [OPTIONS] RESOURCE'] -weight: 10 -toc: true +params: + functions_and_methods: + aliases: [] + returnType: resource.Resource + signatures: ['js.Build [OPTIONS] RESOURCE'] --- The `js.Build` function uses the [evanw/esbuild] package to: @@ -24,8 +18,6 @@ The `js.Build` function uses the [evanw/esbuild] package to: - Minify - Create source maps -[evanw/esbuild]: https://github.com/evanw/esbuild - ```go-html-template {{ with resources.Get "js/main.js" }} {{ $opts := dict @@ -47,16 +39,13 @@ The `js.Build` function uses the [evanw/esbuild] package to: ## Options -###### 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. +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 +format +: (`string`) The output format. One of: `iife`, `cjs`, `esm`. Default is `iife`, a self-executing function, suitable for inclusion as a `<script>` tag. -(`string`) The output format. One of: `iife`, `cjs`, `esm`. Default is `iife`, a self-executing function, suitable for inclusion as a `<script>` tag. - -{{% include "./_common/options.md" %}} +{{% include "/_common/functions/js/options.md" %}} ## Import JS code from the assets directory @@ -99,7 +88,7 @@ And then in your JS file: import * as params from '@params'; ``` -Hugo will, by default, generate a `assets/jsconfig.json` file that maps the imports. This is useful for navigation/intellisense help inside code editors, but if you don't need/want it, you can [turn it off](/getting-started/configuration/#configure-build). +Hugo will, by default, generate a `assets/jsconfig.json` file that maps the imports. This is useful for navigation/intellisense help inside code editors, but if you don't need/want it, you can [turn it off](/configuration/build/). ## Node.js dependencies @@ -109,9 +98,8 @@ Any imports in a file outside `assets` or that does not resolve to a component i The start directory for resolving npm packages (aka. packages that live inside a `node_modules` directory) is always the main project directory. -{{% note %}} -If you're developing a theme/component that is supposed to be imported and depends on dependencies inside `package.json`, we recommend reading about [hugo mod npm pack](/commands/hugo_mod_npm_pack/), a tool to consolidate all the npm dependencies in a project. -{{% /note %}} +> [!note] +> If you're developing a theme/component that is supposed to be imported and depends on dependencies inside `package.json`, we recommend reading about [hugo mod npm pack](/commands/hugo_mod_npm_pack/), a tool to consolidate all the npm dependencies in a project. ## Examples @@ -129,3 +117,5 @@ Or with options: {{ $built := resources.Get "scripts/main.js" | js.Build $opts }} <script src="{{ $built.RelPermalink }}" defer></script> ``` + +[evanw/esbuild]: https://github.com/evanw/esbuild |