diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-01-22 17:07:23 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-01-22 23:43:44 +0100 |
commit | 32b86076ee1c0833b538b84e1cc9e6d79babecf2 (patch) | |
tree | 7332c7ba35372e520fe67fa011747773a1b226d5 /resources/resource_transformers/js/build.go | |
parent | 241b7483ea954653512d4895ad6bacf79ee26ddc (diff) |
js: Add Inject config option
Fixes #8164
Diffstat (limited to 'resources/resource_transformers/js/build.go')
-rw-r--r-- | resources/resource_transformers/js/build.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/resources/resource_transformers/js/build.go b/resources/resource_transformers/js/build.go index ee60aa502..bd126efda 100644 --- a/resources/resource_transformers/js/build.go +++ b/resources/resource_transformers/js/build.go @@ -18,6 +18,7 @@ import ( "io/ioutil" "os" "path" + "path/filepath" "regexp" "strings" @@ -103,6 +104,28 @@ func (t *buildTransformation) Transform(ctx *resources.ResourceTransformationCtx defer os.Remove(buildOptions.Outdir) } + if opts.Inject != nil { + // Resolve the absolute filenames. + for i, ext := range opts.Inject { + impPath := filepath.FromSlash(ext) + if filepath.IsAbs(impPath) { + return errors.Errorf("inject: absolute paths not supported, must be relative to /assets") + } + + m := resolveComponentInAssets(t.c.rs.Assets.Fs, impPath) + + if m == nil { + return errors.Errorf("inject: file %q not found", ext) + } + + opts.Inject[i] = m.Filename() + + } + + buildOptions.Inject = opts.Inject + + } + result := api.Build(buildOptions) if len(result.Errors) > 0 { |