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
This commit is contained in:
Andreas Richter
2020-09-01 10:19:08 -04:00
committed by GitHub
parent cdfd1c99ba
commit c6b661de82
4 changed files with 35 additions and 3 deletions

View File

@@ -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,