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:
authorAndreas Richter <richtera@users.noreply.github.com>2020-09-01 17:19:08 +0300
committerGitHub <noreply@github.com>2020-09-01 17:19:08 +0300
commitc6b661de826f3ed8768a97a5178b4e020cb2ace1 (patch)
tree0ee180ed3e8e57faa2d8a9c78c31aec129558c66 /resources
parentcdfd1c99baa22d69e865294dfcd783811f96c880 (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')
-rw-r--r--resources/resource_transformers/js/build.go19
-rw-r--r--resources/resource_transformers/js/build_test.go14
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{},
+ })
}