Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-01-21 18:52:32 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-01-22 11:03:24 +0300
commite19a046c4be9b0654884259b9df94f41561e4fc3 (patch)
tree391c53358df72b346fbccf57a01dca2eb316da7d /resources
parenta1fe552fc9e622a15010a94281f604eb85bebd84 (diff)
js: Add Shims option
This commit adds a new `shims` option to `js.Build` that allows swapping out a component with another. Fixes #8165
Diffstat (limited to 'resources')
-rw-r--r--resources/resource_transformers/js/options.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/resources/resource_transformers/js/options.go b/resources/resource_transformers/js/options.go
index 5236fe126..a65e67ac0 100644
--- a/resources/resource_transformers/js/options.go
+++ b/resources/resource_transformers/js/options.go
@@ -62,11 +62,14 @@ type Options struct {
Format string
// External dependencies, e.g. "react".
- Externals []string `hash:"set"`
+ Externals []string
// User defined symbols.
Defines map[string]interface{}
+ // Maps a component import to another.
+ Shims map[string]string
+
// User defined params. Will be marshaled to JSON and available as "@params", e.g.
// import * as params from '@params';
Params interface{}
@@ -138,6 +141,13 @@ func createBuildPlugins(c *Client, opts Options) ([]api.Plugin, error) {
fs := c.rs.Assets
resolveImport := func(args api.OnResolveArgs) (api.OnResolveResult, error) {
+ impPath := args.Path
+ if opts.Shims != nil {
+ override, found := opts.Shims[impPath]
+ if found {
+ impPath = override
+ }
+ }
isStdin := args.Importer == stdinImporter
var relDir string
if !isStdin {
@@ -153,8 +163,6 @@ func createBuildPlugins(c *Client, opts Options) ([]api.Plugin, error) {
relDir = filepath.Dir(opts.sourcefile)
}
- impPath := args.Path
-
// Imports not starting with a "." is assumed to live relative to /assets.
// Hugo makes no assumptions about the directory structure below /assets.
if relDir != "" && strings.HasPrefix(impPath, ".") {