mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
28bd06265e
a26d0e610 Add documentation to js.Build (#1175) 439a22c3e Update index.md 7a779b39a Hugo 0.74.2 07cb5740c Merge branch 'temp742' abcea676c releaser: Add release notes to /docs for release of 0.74.2 e0dcdbfea Revert "Adding an issue link to the issue creation workflow (#1023)" 21c7131f1 Adding an issue link to the issue creation workflow (#1023) 922afb18b Update index.md b9512b192 Update index.md b7af5993c Update index.md 816f864b6 Release 0.74.1 1732f3461 Merge branch 'temp741' d473f21c1 releaser: Add release notes to /docs for release of 0.74.1 bb234e9cd Add release notes 0.74.0 5cb3166d4 releaser: Add release notes to /docs for release of 0.74.0 7f35a3800 Merge commit '823ce055ed3356da37e9ec4ac70446bdbbaa8de8' 4b7054be5 docs: Regenerate docs helper 1d86f0aed Merge commit '6aa5c9117fd34644459ea9bcfb1b3f5010658d5d' 068b2ab28 Update formats.md doc for new allowed extensions. d71ed99d3 Add support for inline partials efe0e549c Rework external asciidoctor integration git-subtree-dir: docs git-subtree-split: a26d0e610457c7942fd79e7abdd78021f9401796
1.9 KiB
1.9 KiB
title | description | date | publishdate | lastmod | categories | keywords | menu | weight | sections_weight | draft | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
JavaScript Building | Hugo Pipes can process JavaScript files with [ESBuild](https://github.com/evanw/esbuild). | 2020-07-20 | 2020-07-20 | 2020-07-20 |
|
|
45 | 45 | false |
Any JavaScript resource file can be transpiled and "tree shaken" using js.Build
which takes for argument either a string for the filepath or a dict of options listed below.
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.
- minify [bool]
- Let
js.Build
handle the minification. - target [string]
- The language target.
One of:
es2015
,es2016
,es2017
,es2018
,es2019
,es2020
oresnext
. Default isesnext
. - externals [slice]
- External dependencies. If a dependency should not be included in the bundle (Ex. library loaded from a CDN.), it should be listed here.
{{ $externals := slice "react" "react-dom" }}
- 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.
{{ $defines := dict "process.env.NODE_ENV" `"development"` }}
Examples
{{ $built := resources.Get "js/index.js" | js.Build "main.js" }}
Or with options:
{{ $externals := slice "react" "react-dom" }}
{{ $defines := dict "process.env.NODE_ENV" `"development"` }}
{{ $opts := dict "targetPath" "main.js" "externals" $externals "defines" $defines }}
{{ $built := resources.Get "scripts/main.js" | js.Build $opts }}
<script type="text/javascript" src="{{ $built.RelPermalink }}" defer></script>