mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
js: Fix js.Batch for multihost setups
Note that this is an unreleased feature. Fixes #13151
This commit is contained in:
@@ -184,6 +184,69 @@ func TestBatchEditScriptParam(t *testing.T) {
|
||||
b.AssertFileContent("public/mybatch/mygroup.js", "param-p1-main-edited")
|
||||
}
|
||||
|
||||
func TestBatchMultiHost(t *testing.T) {
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ["taxonomy", "term", "section"]
|
||||
[languages]
|
||||
[languages.en]
|
||||
weight = 1
|
||||
baseURL = "https://example.com/en"
|
||||
[languages.fr]
|
||||
weight = 2
|
||||
baseURL = "https://example.com/fr"
|
||||
disableLiveReload = true
|
||||
-- assets/js/styles.css --
|
||||
body {
|
||||
background-color: red;
|
||||
}
|
||||
-- assets/js/main.js --
|
||||
import * as foo from 'mylib';
|
||||
console.log("Hello, Main!");
|
||||
-- assets/js/runner.js --
|
||||
console.log("Hello, Runner!");
|
||||
-- node_modules/mylib/index.js --
|
||||
console.log("Hello, My Lib!");
|
||||
-- layouts/index.html --
|
||||
Home.
|
||||
{{ $batch := (js.Batch "mybatch") }}
|
||||
{{ with $batch.Config }}
|
||||
{{ .SetOptions (dict
|
||||
"params" (dict "id" "config")
|
||||
"sourceMap" ""
|
||||
)
|
||||
}}
|
||||
{{ end }}
|
||||
{{ with (templates.Defer (dict "key" "global")) }}
|
||||
Defer:
|
||||
{{ $batch := (js.Batch "mybatch") }}
|
||||
{{ range $k, $v := $batch.Build.Groups }}
|
||||
{{ range $kk, $vv := . -}}
|
||||
{{ $k }}: {{ .RelPermalink }}
|
||||
{{ end }}
|
||||
{{ end -}}
|
||||
{{ end }}
|
||||
{{ $batch := (js.Batch "mybatch") }}
|
||||
{{ with $batch.Group "mygroup" }}
|
||||
{{ with .Runner "run" }}
|
||||
{{ .SetOptions (dict "resource" (resources.Get "js/runner.js")) }}
|
||||
{{ end }}
|
||||
{{ with .Script "main" }}
|
||||
{{ .SetOptions (dict "resource" (resources.Get "js/main.js") "params" (dict "p1" "param-p1-main" )) }}
|
||||
{{ end }}
|
||||
{{ with .Instance "main" "i1" }}
|
||||
{{ .SetOptions (dict "params" (dict "title" "Instance 1")) }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
`
|
||||
b := hugolib.Test(t, files, hugolib.TestOptWithOSFs())
|
||||
b.AssertPublishDir(
|
||||
"en/mybatch/chunk-TOZKWCDE.js", "en/mybatch/mygroup.js ",
|
||||
"fr/mybatch/mygroup.js", "fr/mybatch/chunk-TOZKWCDE.js")
|
||||
}
|
||||
|
||||
func TestBatchRenameBundledScript(t *testing.T) {
|
||||
files := jsBatchFilesTemplate
|
||||
b := hugolib.TestRunning(t, files, hugolib.TestOptWithOSFs())
|
||||
|
Reference in New Issue
Block a user