mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-14 20:33:59 +02:00
js: Add Shims option
This commit adds a new `shims` option to `js.Build` that allows swapping out a component with another. Fixes #8165
This commit is contained in:
@@ -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, ".") {
|
||||
|
Reference in New Issue
Block a user