1.8 KiB
title, description, date, group, layout
title | description | date | group | layout |
---|---|---|---|---|
Scripts | Automatically bundle local and external JavaScript files into a single file. | 2023-01-21 | configuration | docs |
Hinode bundles local and external JavaScript into a single file. By utilizing [npm]({{< ref "overview" >}}), external JavaScript files are automatically ingested and kept up to date.
Build pipeline
Hinodes uses npm and mounted folders to create a flexibile virtual file system that is automatically kept up to date. Review the [overview]({{< ref "overview" >}}) for a detailed explanation. The build pipeline of the JavaScript files consists of four steps.
-
Add the local JavaScript files
Add the local JavaScript files to the
assets/js
folder with a recognizable filename. -
Mount the JavaScript files maintained within a node package
Make JavaScripts defined in node packages available by mounting them into the
assets/js/vendor
folder. Define the mount points inconfig/_default/config.toml
. -
Bundle the JavaScript files
The partial
partials/footer/scripts.html
bundles all files that end with.js
recursively into a single file calledjs/main.bundle.js
. In production mode, the output is minified and linked to with a [fingerprint]({{< param "links.hugo_fingerprint" >}}). -
Link to the JavaScript in the base layout
Hinode's base layout
layouts/_default/baseof.html
imports the bundled JavaScript file in the footer. The file is cached to improve performance.
Example
Mount the external JavaScript files to Hugo's virtual file system within the file config/_default/config.toml
. The current configuration imports the relevant files of [Bootstrap]({{< param "links.bootstrap" >}}) and [FlexSearch]({{< param "links.flexsearch" >}}).
{{< toml-docs name="javascript" file="config/_default/config.toml" >}}