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>2021-01-18 12:38:09 +0300
committerGitHub <noreply@github.com>2021-01-18 12:38:09 +0300
commit2c8b5d9165011c4b24b494e661ae60dfc7bb7d1b (patch)
tree1fccfe098c0ad5a85a030ba918914ea4191c658c /hugolib
parent0004a733c85cee991a8a170e93cd69c326cc8f2f (diff)
pipes: Add external source map support to js.Build and Babel
Fixes #8132
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/js_test.go8
-rw-r--r--hugolib/resource_chain_babel_test.go33
2 files changed, 39 insertions, 2 deletions
diff --git a/hugolib/js_test.go b/hugolib/js_test.go
index a1b74a871..145a057c1 100644
--- a/hugolib/js_test.go
+++ b/hugolib/js_test.go
@@ -109,14 +109,16 @@ document.body.textContent = greeter(user);`
JS: {{ template "print" $js }}
{{ $jsx := resources.Get "js/myjsx.jsx" | js.Build $options }}
JSX: {{ template "print" $jsx }}
-{{ $ts := resources.Get "js/myts.ts" | js.Build }}
+{{ $ts := resources.Get "js/myts.ts" | js.Build (dict "sourcemap" "inline")}}
TS: {{ template "print" $ts }}
-
+{{ $ts2 := resources.Get "js/myts.ts" | js.Build (dict "sourcemap" "external" "TargetPath" "js/myts2.js")}}
+TS2: {{ template "print" $ts2 }}
{{ define "print" }}RelPermalink: {{.RelPermalink}}|MIME: {{ .MediaType }}|Content: {{ .Content | safeJS }}{{ end }}
`)
jsDir := filepath.Join(workDir, "assets", "js")
+ fmt.Println(workDir)
b.Assert(os.MkdirAll(jsDir, 0777), qt.IsNil)
b.Assert(os.Chdir(workDir), qt.IsNil)
b.WithSourceFile("package.json", packageJSON)
@@ -133,6 +135,8 @@ TS: {{ template "print" $ts }}
b.Build(BuildCfg{})
+ b.AssertFileContent("public/js/myts.js", `//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJz`)
+ b.AssertFileContent("public/js/myts2.js.map", `"version": 3,`)
b.AssertFileContent("public/index.html", `
console.log(&#34;included&#34;);
if (hasSpace.test(string))
diff --git a/hugolib/resource_chain_babel_test.go b/hugolib/resource_chain_babel_test.go
index d5e99cd17..77c81f9ca 100644
--- a/hugolib/resource_chain_babel_test.go
+++ b/hugolib/resource_chain_babel_test.go
@@ -80,6 +80,15 @@ class Car {
}
`
+ js2 := `
+/* A Car2 */
+class Car2 {
+ constructor(brand) {
+ this.carname = brand;
+ }
+}
+`
+
workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-test-babel")
c.Assert(err, qt.IsNil)
defer clean()
@@ -103,11 +112,18 @@ class Car {
{{ $transpiled := resources.Get "js/main.js" | babel -}}
Transpiled: {{ $transpiled.Content | safeJS }}
+{{ $transpiled := resources.Get "js/main2.js" | babel (dict "sourceMap" "inline") -}}
+Transpiled2: {{ $transpiled.Content | safeJS }}
+
+{{ $transpiled := resources.Get "js/main2.js" | babel (dict "sourceMap" "external") -}}
+Transpiled3: {{ $transpiled.Permalink }}
+
`)
jsDir := filepath.Join(workDir, "assets", "js")
b.Assert(os.MkdirAll(jsDir, 0777), qt.IsNil)
b.WithSourceFile("assets/js/main.js", js)
+ b.WithSourceFile("assets/js/main2.js", js2)
b.WithSourceFile("package.json", packageJSON)
b.WithSourceFile("babel.config.js", babelConfig)
@@ -129,4 +145,21 @@ var Car = function Car(brand) {
this.carname = brand;
};
`)
+ b.AssertFileContent("public/index.html", `
+var Car2 = function Car2(brand) {
+ _classCallCheck(this, Car2);
+
+ this.carname = brand;
+};
+`)
+ b.AssertFileContent("public/js/main2.js", `
+var Car2 = function Car2(brand) {
+ _classCallCheck(this, Car2);
+
+ this.carname = brand;
+};
+`)
+ b.AssertFileContent("public/js/main2.js.map", `{"version":3,`)
+ b.AssertFileContent("public/index.html", `
+//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozL`)
}