mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-02 08:30:07 +03:00
Merge commit '5be51ac3db
'
This commit is contained in:
commit
653f1c1d46
987 changed files with 12379 additions and 14083 deletions
|
@ -3,17 +3,11 @@ title: js.Babel
|
|||
description: Compile the given JavaScript resource with Babel.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [babel]
|
||||
related:
|
||||
- functions/js/Batch
|
||||
- functions/js/Build
|
||||
- functions/resources/Fingerprint
|
||||
- functions/resources/Minify
|
||||
returnType: resource.Resource
|
||||
signatures: ['js.Babel [OPTIONS] RESOURCE']
|
||||
weight: 30
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [babel]
|
||||
returnType: resource.Resource
|
||||
signatures: ['js.Babel [OPTIONS] RESOURCE']
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
|
@ -37,18 +31,21 @@ toc: true
|
|||
|
||||
## Setup
|
||||
|
||||
Step 1
|
||||
: Install [Node.js](https://nodejs.org/en/download)
|
||||
### Step 1
|
||||
|
||||
Step 2
|
||||
: Install the required Node.js packages in the root of your project.
|
||||
Install [Node.js](https://nodejs.org/en/download)
|
||||
|
||||
### Step 2
|
||||
|
||||
Install the required Node.js packages in the root of your project.
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/core @babel/cli
|
||||
```
|
||||
|
||||
Step 3
|
||||
: Add the babel executable to Hugo's `security.exec.allow` list in your site configuration:
|
||||
### Step 3
|
||||
|
||||
Add the babel executable to Hugo's `security.exec.allow` list in your site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[security.exec]
|
||||
|
@ -75,32 +72,28 @@ module.exports = {
|
|||
|
||||
## Options
|
||||
|
||||
###### compact
|
||||
compact
|
||||
: (`bool`) Whether to remove optional newlines and whitespace. Enabled when `minified` is `true`. Default is `false`
|
||||
|
||||
(`bool`) Whether to remove optional newlines and whitespace. Enabled when `minified` is `true`. Default is `false`
|
||||
config
|
||||
: (`string`) Path to the Babel configuration file. Hugo will, by default, look for a `babel.config.js` file in the root of your project. See [details](https://babeljs.io/docs/en/configuration).
|
||||
|
||||
###### config
|
||||
minified
|
||||
: (`bool`) Whether to minify the compiled code. Enables the `compact` option. Default is `false`.
|
||||
|
||||
(`string`) Path to the Babel configuration file. Hugo will, by default, look for a `babel.config.js` file in the root of your project. See [details](https://babeljs.io/docs/en/configuration).
|
||||
noBabelrc
|
||||
: (`string`) Whether to ignore `.babelrc` and `.babelignore` files. Default is `false`.
|
||||
|
||||
###### minified
|
||||
noComments
|
||||
: (`bool`) Whether to remove comments. Default is `false`.
|
||||
|
||||
(`bool`) Whether to minify the compiled code. Enables the `compact` option. Default is `false`.
|
||||
sourceMap
|
||||
: (`string`) Whether to generate source maps, one of `external`, `inline`, or `none`. Default is `none`.
|
||||
|
||||
###### noBabelrc
|
||||
verbose
|
||||
: (`bool`) Whether to enable verbose logging. Default is `false`
|
||||
|
||||
(`string`) Whether to ignore `.babelrc` and `.babelignore` files. Default is `false`.
|
||||
|
||||
###### noComments
|
||||
|
||||
(`bool`) Whether to remove comments. Default is `false`.
|
||||
|
||||
###### sourceMap
|
||||
|
||||
(`string`) Whether to generate source maps, one of `external`, `inline`, or `none`. Default is `none`.
|
||||
|
||||
<!-- In the above, technically "none" is not one of the enumerated values, but it has the same effect and is easier to document than an empty string. -->
|
||||
|
||||
###### verbose
|
||||
|
||||
(`bool`) Whether to enable verbose logging. Default is `false`
|
||||
<!--
|
||||
In the above, technically "none" is not one of the enumerated sourceMap
|
||||
values but it has the same effect and is easier to document than an empty string.
|
||||
-->
|
||||
|
|
|
@ -3,40 +3,33 @@ title: js.Batch
|
|||
description: Build JavaScript bundle groups with global code splitting and flexible hooks/runners setup.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/js/Build
|
||||
- functions/js/Babel
|
||||
- functions/resources/Fingerprint
|
||||
- functions/resources/Minify
|
||||
returnType: js.Batcher
|
||||
signatures: ['js.Batch [ID]']
|
||||
weight: 20
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: js.Batcher
|
||||
signatures: ['js.Batch [ID]']
|
||||
---
|
||||
|
||||
{{% note %}}
|
||||
For a runnable example of this feature, see [this test and demo repo](https://github.com/bep/hugojsbatchdemo/).
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> For a runnable example of this feature, see [this test and demo repo](https://github.com/bep/hugojsbatchdemo/).
|
||||
|
||||
The Batch `ID` is used to create the base directory for this batch. Forward slashes are allowed. `js.Batch` returns an object with an API with this structure:
|
||||
|
||||
* [Group]
|
||||
* [Script]
|
||||
* [SetOptions]
|
||||
* [Instance]
|
||||
* [SetOptions]
|
||||
* [Runner]
|
||||
* [SetOptions]
|
||||
* [Config]
|
||||
* [SetOptions]
|
||||
- [Group]
|
||||
- [Script]
|
||||
- [SetOptions]
|
||||
- [Instance]
|
||||
- [SetOptions]
|
||||
- [Runner]
|
||||
- [SetOptions]
|
||||
- [Config]
|
||||
- [SetOptions]
|
||||
|
||||
## Group
|
||||
|
||||
The `Group` method take an `ID` (`string`) as argument. No slashes. It returns an object with these methods:
|
||||
|
||||
#### Script
|
||||
### Script
|
||||
|
||||
The `Script` method takes an `ID` (`string`) as argument. No slashes. It returns an [OptionsSetter] that can be used to set [script options] for this script.
|
||||
|
||||
|
@ -50,9 +43,9 @@ The `Script` method takes an `ID` (`string`) as argument. No slashes. It returns
|
|||
{{ end }}
|
||||
```
|
||||
|
||||
`SetOptions` takes a [script options] map. Note that if you want the script to be handled by a [runner], you need to set the `export` option to match what you want to pass on to the runner (default is `*`).
|
||||
`SetOptions` takes a [script options] map. Note that if you want the script to be handled by a [runner], you need to set the `export` option to match what you want to pass on to the runner (default is `*`).
|
||||
|
||||
#### Instance
|
||||
### Instance
|
||||
|
||||
The `Instance` method takes two `string` arguments `SCRIPT_ID` and `INSTANCE_ID`. No slashes. It returns an [OptionsSetter] that can be used to set [params options] for this instance.
|
||||
|
||||
|
@ -68,7 +61,7 @@ The `Instance` method takes two `string` arguments `SCRIPT_ID` and `INSTANCE_ID`
|
|||
|
||||
`SetOptions` takes a [params options] map. The instance options will be passed to any [runner] script in the same group, as JSON.
|
||||
|
||||
#### Runner
|
||||
### Runner
|
||||
|
||||
The `Runner` method takes an `ID` (`string`) as argument. No slashes. It returns an [OptionsSetter] that can be used to set [script options] for this runner.
|
||||
|
||||
|
@ -131,34 +124,34 @@ import * as ReactDOM from 'react-dom/client';
|
|||
import * as React from 'react';
|
||||
|
||||
export default function Run(group) {
|
||||
console.log('Running react-create-elements.js', group);
|
||||
const scripts = group.scripts;
|
||||
for (const script of scripts) {
|
||||
for (const instance of script.instances) {
|
||||
/* This is a convention in this project. */
|
||||
let elId = `${script.id}-${instance.id}`;
|
||||
let el = document.getElementById(elId);
|
||||
if (!el) {
|
||||
console.warn(`Element with id ${elId} not found`);
|
||||
continue;
|
||||
}
|
||||
const root = ReactDOM.createRoot(el);
|
||||
const reactEl = React.createElement(script.binding, instance.params);
|
||||
root.render(reactEl);
|
||||
}
|
||||
}
|
||||
console.log('Running react-create-elements.js', group);
|
||||
const scripts = group.scripts;
|
||||
for (const script of scripts) {
|
||||
for (const instance of script.instances) {
|
||||
/* This is a convention in this project. */
|
||||
let elId = `${script.id}-${instance.id}`;
|
||||
let el = document.getElementById(elId);
|
||||
if (!el) {
|
||||
console.warn(`Element with id ${elId} not found`);
|
||||
continue;
|
||||
}
|
||||
const root = ReactDOM.createRoot(el);
|
||||
const reactEl = React.createElement(script.binding, instance.params);
|
||||
root.render(reactEl);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Config
|
||||
### Config
|
||||
|
||||
Returns an [OptionsSetter] that can be used to set [build options] for the batch.
|
||||
|
||||
These are mostly the same as for `js.Build`, but note that:
|
||||
|
||||
* `targetPath` is set automatically (there may be multiple outputs).
|
||||
* `format` must be `esm`, currently the only format supporting [code splitting].
|
||||
* `params` will be available in the `@params/config` namespace in the scripts. This way you can import both the [script] or [runner] params and the [config] params with:
|
||||
- `targetPath` is set automatically (there may be multiple outputs).
|
||||
- ``format` must be `esm`, currently the only format supporting [code splitting].
|
||||
- ``params` will be available in the `@params/config` namespace in the scripts. This way you can import both the [script] or [runner] params and the [config] params with:
|
||||
|
||||
```js
|
||||
import * as params from "@params";
|
||||
|
@ -185,14 +178,14 @@ Setting the `Config` for a batch can be done from any template (including shortc
|
|||
|
||||
## Options
|
||||
|
||||
### Build Options
|
||||
### Build options
|
||||
|
||||
format
|
||||
: (`string`) Currently only `esm` is supported in [ESBuild's code splitting].
|
||||
: (`string`) Currently only `esm` is supported in ESBuild's [code splitting].
|
||||
|
||||
{{% include "./_common/options.md" %}}
|
||||
{{% include "/_common/functions/js/options.md" %}}
|
||||
|
||||
### Script Options
|
||||
### Script options
|
||||
|
||||
resource
|
||||
: The resource to build. This can be a file resource or a virtual resource.
|
||||
|
@ -205,18 +198,17 @@ importContext
|
|||
|
||||
params
|
||||
: A map of parameters that will be passed to the script as JSON. These gets bound to the `@params` namespace:
|
||||
```js
|
||||
import * as params from '@params';
|
||||
```
|
||||
|
||||
### Script Options
|
||||
```js
|
||||
import * as params from '@params';
|
||||
```
|
||||
|
||||
### Params Options
|
||||
### Params options
|
||||
|
||||
params
|
||||
: A map of parameters that will be passed to the script as JSON.
|
||||
: A map of parameters that will be passed to the script as JSON.
|
||||
|
||||
### Import Context
|
||||
### Import context
|
||||
|
||||
Hugo will, by default, first try to resolve any import in [assets](/hugo-pipes/introduction/#asset-directory) and, if not found, let [ESBuild] resolve it (e.g. from `node_modules`). The `importContext` option can be used to set the first context for resolving imports. A common use of this is to resolve imports inside a [page bundle](/content-management/page-bundles/).
|
||||
|
||||
|
@ -243,20 +235,17 @@ An `OptionsSetter` is a special object that is returned once only. This means th
|
|||
|
||||
The `Build` method returns an object with the following structure:
|
||||
|
||||
* Groups (map)
|
||||
* [`Resources`]
|
||||
- Groups (map)
|
||||
- [`Resources`]
|
||||
|
||||
Eeach [`Resource`] will be of media type `application/javascript` or `text/css`.
|
||||
Each [`Resource`] will be of media type `application/javascript` or `text/css`.
|
||||
|
||||
In a template you would typically handle one group with a given `ID` (e.g. scripts for the current section). Because of the concurrent build, this needs to be done in a [`templates.Defer`] block:
|
||||
In a template you would typically handle one group with a given `ID` (e.g. scripts for the current section). Because of the concurrent build, this needs to be done in a [`templates.Defer`] block:
|
||||
|
||||
{{% note %}}
|
||||
The [`templates.Defer`] acts as a synchronisation point to handle scripts added concurrently by different templates. If you have a setup with where the batch is created in one go (in one template), you don't need it.
|
||||
|
||||
See [this discussion](https://discourse.gohugo.io/t/js-batch-with-simple-global-script/53002/5?u=bep) for more.
|
||||
|
||||
[`templates.Defer`]: /functions/templates/defer/
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> The [`templates.Defer`] acts as a synchronisation point to handle scripts added concurrently by different templates. If you have a setup with where the batch is created in one go (in one template), you don't need it.
|
||||
>
|
||||
> See [this discussion](https://discourse.gohugo.io/t/js-batch-with-simple-global-script/53002/5?u=bep) for more.
|
||||
|
||||
```go-html-template
|
||||
{{ $group := .group }}
|
||||
|
@ -279,10 +268,10 @@ See [this discussion](https://discourse.gohugo.io/t/js-batch-with-simple-global-
|
|||
|
||||
## Known Issues
|
||||
|
||||
In the official documentation for [ESBuild's code splitting], there's a warning note in the header. The two issues are:
|
||||
In the official documentation for ESBuild's [code splitting], there's a warning note in the header. The two issues are:
|
||||
|
||||
* `esm` is currently the only implemented output format. This means that it will not work for very old browsers. See [caniuse](https://caniuse.com/?search=ESM).
|
||||
* There's a known import ordering issue.
|
||||
- `esm` is currently the only implemented output format. This means that it will not work for very old browsers. See [caniuse](https://caniuse.com/?search=ESM).
|
||||
- There's a known import ordering issue.
|
||||
|
||||
We have not seen the ordering issue as a problem during our [extensive testing](https://github.com/bep/hugojsbatchdemo) of this new feature with different libraries. There are two main cases:
|
||||
|
||||
|
@ -296,28 +285,23 @@ import './lib2.js';
|
|||
import './lib1.js';
|
||||
|
||||
console.log('entrypoints-workaround.js');
|
||||
|
||||
```
|
||||
|
||||
[build options]: #build-options
|
||||
[`Resource`]: /methods/resource/
|
||||
[`Resources`]: /methods/page/resources/
|
||||
[`Resources.Mount`]: /methods/page/resources/#mount
|
||||
[`Resources`]: /methods/page/resources/
|
||||
[`templates.Defer`]: /functions/templates/defer/
|
||||
[`templates.Defer`]: /functions/templates/defer/
|
||||
[build options]: #build-options
|
||||
[code splitting]: https://esbuild.github.io/api/#splitting
|
||||
[config]: #config
|
||||
[ESBuild's code splitting]: https://esbuild.github.io/api/#splitting
|
||||
[ESBuild]: https://github.com/evanw/esbuild
|
||||
[group]: #group
|
||||
[instance]: #instance
|
||||
[JavaScript import]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
|
||||
[js.Batch Demo Repo]: https://github.com/bep/hugojsbatchdemo/
|
||||
[map]: /functions/collections/dictionary/
|
||||
[OptionsSetter]: #optionssetter
|
||||
[page bundles]: /content-management/page-bundles/
|
||||
[params options]: #params-options
|
||||
[runner]: #runner
|
||||
[script options]: #script-options
|
||||
[script]: #script
|
||||
[script options]: #script-options
|
||||
[SetOptions]: #optionssetter
|
||||
[with]: /functions/go-template/with/
|
||||
|
|
|
@ -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
|
||||
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.
|
||||
|
||||
(`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 `<script>` tag.
|
||||
|
||||
###### format
|
||||
|
||||
(`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
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
---
|
||||
cascade:
|
||||
_build:
|
||||
list: never
|
||||
publishResources: false
|
||||
render: never
|
||||
---
|
||||
|
||||
<!--
|
||||
Files within this headless branch bundle are Markdown snippets. Each file must contain front matter delimiters, though front matter fields are not required.
|
||||
|
||||
Include the rendered content using the "include" shortcode.
|
||||
-->
|
|
@ -1,129 +0,0 @@
|
|||
---
|
||||
_comment: Do not remove front matter.
|
||||
---
|
||||
|
||||
###### params
|
||||
|
||||
(`map` or `slice`) Params that can be imported as JSON in your JS files, e.g.
|
||||
|
||||
```go-html-template
|
||||
{{ $js := resources.Get "js/main.js" | js.Build (dict "params" (dict "api" "https://example.org/api")) }}
|
||||
```
|
||||
And then in your JS file:
|
||||
|
||||
```js
|
||||
import * as params from '@params';
|
||||
```
|
||||
|
||||
Note that this is meant for small data sets, e.g. configuration settings. For larger data, please put/mount the files into `assets` and import them directly.
|
||||
|
||||
###### minify
|
||||
|
||||
(`bool`) Let `js.Build` handle the minification.
|
||||
|
||||
###### loaders
|
||||
|
||||
{{< new-in 0.140.0 />}}
|
||||
|
||||
(`map`) Configuring a loader for a given file type lets you load that file type with an import statement or a require call. For example configuring the .png file extension to use the data URL loader means importing a .png file gives you a data URLcontaining the contents of that image. Loaders available are `none`, `base64`, `binary`, `copy`, `css`, `dataurl`, `default`, `empty`, `file`, `global-css`, `js`, `json`, `jsx`, `local-css`, `text`, `ts`, `tsx`. See https://esbuild.github.io/api/#loader.
|
||||
|
||||
###### inject
|
||||
|
||||
(`slice`) This option allows you to automatically replace a global variable with an import from another file. The path names must be relative to `assets`. See https://esbuild.github.io/api/#inject.
|
||||
|
||||
###### shims
|
||||
|
||||
(`map`) This option allows swapping out a component with another. A common use case is to load dependencies like React from a CDN (with _shims_) when in production, but running with the full bundled `node_modules` dependency during development:
|
||||
|
||||
```go-html-template
|
||||
{{ $shims := dict "react" "js/shims/react.js" "react-dom" "js/shims/react-dom.js" }}
|
||||
{{ $js = $js | js.Build dict "shims" $shims }}
|
||||
```
|
||||
|
||||
The _shim_ files may look like these:
|
||||
|
||||
```js
|
||||
// js/shims/react.js
|
||||
module.exports = window.React;
|
||||
```
|
||||
|
||||
```js
|
||||
// js/shims/react-dom.js
|
||||
module.exports = window.ReactDOM;
|
||||
```
|
||||
|
||||
With the above, these imports should work in both scenarios:
|
||||
|
||||
```js
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom/client';
|
||||
```
|
||||
|
||||
###### target
|
||||
|
||||
(`string`) The language target. One of: `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020` or `esnext`. Default is `esnext`.
|
||||
|
||||
###### platform
|
||||
|
||||
{{< new-in 0.140.0 />}}
|
||||
|
||||
(`string`) One of `browser`, `node`, `neutral`. Default is `browser`. See https://esbuild.github.io/api/#platform.
|
||||
|
||||
###### externals
|
||||
|
||||
(`slice`) External dependencies. Use this to trim dependencies you know will never be executed. See https://esbuild.github.io/api/#external.
|
||||
|
||||
###### defines
|
||||
|
||||
(`map`) Allow to define a set of string replacement to be performed when building. Should be a map where each key is to be replaced by its value.
|
||||
|
||||
```go-html-template
|
||||
{{ $defines := dict "process.env.NODE_ENV" `"development"` }}
|
||||
```
|
||||
|
||||
##### drop
|
||||
|
||||
Edit your source code before building to drop certain constructs: One of `debugger` or `console`.
|
||||
|
||||
{{< new-in 0.144.0 />}}
|
||||
|
||||
See https://esbuild.github.io/api/#drop
|
||||
|
||||
###### sourceMap
|
||||
|
||||
(`string`) Whether to generate `inline`, `linked` or `external` source maps from esbuild. Linked and external source maps will be written to the target with the output file name + ".map". When `linked` a `sourceMappingURL` will also be written to the output file. By default, source maps are not created. Note that the `linked` option was added in Hugo 0.140.0.
|
||||
|
||||
###### sourcesContent
|
||||
|
||||
{{< new-in 0.140.0 />}}
|
||||
|
||||
(`bool`) Whether to include the content of the source files in the source map. By default, this is `true`.
|
||||
|
||||
###### JSX
|
||||
|
||||
{{< new-in 0.124.0 />}}
|
||||
|
||||
(`string`) How to handle/transform JSX syntax. One of: `transform`, `preserve`, `automatic`. Default is `transform`. Notably, the `automatic` transform was introduced in React 17+ and will cause the necessary JSX helper functions to be imported automatically. See https://esbuild.github.io/api/#jsx.
|
||||
|
||||
###### JSXImportSource
|
||||
|
||||
{{< new-in 0.124.0 />}}
|
||||
|
||||
(`string`) Which library to use to automatically import its JSX helper functions from. This only works if `JSX` is set to `automatic`. The specified library needs to be installed through npm and expose certain exports. See https://esbuild.github.io/api/#jsx-import-source.
|
||||
|
||||
The combination of `JSX` and `JSXImportSource` is helpful if you want to use a non-React JSX library like Preact, e.g.:
|
||||
|
||||
```go-html-template
|
||||
{{ $js := resources.Get "js/main.jsx" | js.Build (dict "JSX" "automatic" "JSXImportSource" "preact") }}
|
||||
```
|
||||
|
||||
With the above, you can use Preact components and JSX without having to manually import `h` and `Fragment` every time:
|
||||
|
||||
```jsx
|
||||
import { render } from 'preact';
|
||||
|
||||
const App = () => <>Hello world!</>;
|
||||
|
||||
const container = document.getElementById('app');
|
||||
if (container) render(<App />, container);
|
||||
```
|
|
@ -1,12 +1,7 @@
|
|||
---
|
||||
title: JavaScript functions
|
||||
linkTitle: js
|
||||
description: Template functions to work with JavaScript and TypeScript files.
|
||||
description: Use these functions to work with JavaScript and TypeScript files.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to work with JavaScript and TypeScript files.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue