pipes: Add external source map support to js.Build and Babel

Fixes #8132
This commit is contained in:
Andreas Richter
2021-01-18 04:38:09 -05:00
committed by GitHub
parent 0004a733c8
commit 2c8b5d9165
6 changed files with 138 additions and 4 deletions

View File

@@ -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("included");
if (hasSpace.test(string))

View File

@@ -78,6 +78,15 @@ class Car {
this.carname = brand;
}
}
`
js2 := `
/* A Car2 */
class Car2 {
constructor(brand) {
this.carname = brand;
}
}
`
workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-test-babel")
@@ -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`)
}