diff options
author | Andreas Richter <richtera@users.noreply.github.com> | 2020-09-01 10:19:08 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-01 16:19:08 +0200 |
commit | c6b661de826f3ed8768a97a5178b4e020cb2ace1 (patch) | |
tree | 0ee180ed3e8e57faa2d8a9c78c31aec129558c66 /resources/resource_transformers | |
parent | cdfd1c99baa22d69e865294dfcd783811f96c880 (diff) |
js.Build: Add SourceMap flag with inline option
Added a flag to allow turning on sourcemap in ESBuild. The current support
can only support inline or true as value for sourcemap. This is because
the way ESBuild is invoked it doesn't have a separate output path
to write the mapfile external to the asset pipeline. Add disable for "" and "0".
Add test script and make sure mage check passes.
Fixes #7607
Diffstat (limited to 'resources/resource_transformers')
-rw-r--r-- | resources/resource_transformers/js/build.go | 19 | ||||
-rw-r--r-- | resources/resource_transformers/js/build_test.go | 14 |
2 files changed, 31 insertions, 2 deletions
diff --git a/resources/resource_transformers/js/build.go b/resources/resource_transformers/js/build.go index 8e0c7c130..e4b4b1c20 100644 --- a/resources/resource_transformers/js/build.go +++ b/resources/resource_transformers/js/build.go @@ -42,6 +42,9 @@ type Options struct { // Whether to minify to output. Minify bool + // Whether to write mapfiles (currently inline only) + SourceMap string + // The language target. // One of: es2015, es2016, es2017, es2018, es2019, es2020 or esnext. // Default is esnext. @@ -217,12 +220,24 @@ func toBuildOptions(opts Options) (buildOptions api.BuildOptions, err error) { defines = cast.ToStringMapString(opts.Defines) } + var sourceMap api.SourceMap + switch opts.SourceMap { + case "inline": + sourceMap = api.SourceMapInline + case "": + sourceMap = api.SourceMapNone + default: + err = fmt.Errorf("unsupported sourcemap type: %q", opts.SourceMap) + return + } + buildOptions = api.BuildOptions{ Outfile: "", Bundle: true, - Target: target, - Format: format, + Target: target, + Format: format, + Sourcemap: sourceMap, MinifyWhitespace: opts.Minify, MinifyIdentifiers: opts.Minify, diff --git a/resources/resource_transformers/js/build_test.go b/resources/resource_transformers/js/build_test.go index ee97dede5..c04c0ed12 100644 --- a/resources/resource_transformers/js/build_test.go +++ b/resources/resource_transformers/js/build_test.go @@ -63,4 +63,18 @@ func TestToBuildOptions(t *testing.T) { Stdin: &api.StdinOptions{}, }) + opts, err = toBuildOptions(Options{ + Target: "es2018", Format: "cjs", Minify: true, mediaType: media.JavascriptType, + SourceMap: "inline"}) + c.Assert(err, qt.IsNil) + c.Assert(opts, qt.DeepEquals, api.BuildOptions{ + Bundle: true, + Target: api.ES2018, + Format: api.FormatCommonJS, + MinifyIdentifiers: true, + MinifySyntax: true, + MinifyWhitespace: true, + Sourcemap: api.SourceMapInline, + Stdin: &api.StdinOptions{}, + }) } |