css: Make css.Build's file-loader URLs absolute to web context root

When CSS imports assets via the file loader (fonts, images), the emitted
URLs were relative to the CSS output directory. That broke when the CSS
was inlined into HTML, since browsers then resolved the URLs against the
page rather than the CSS file.

Set esbuild's PublicPath to the CSS output directory joined with the
site base path so URLs work whether the CSS is published as a file or
inlined.

Fixes #14849
This commit is contained in:
Bjørn Erik Pedersen
2026-05-08 16:48:28 +02:00
parent 7011239205
commit e51e761d9c
8 changed files with 226 additions and 22 deletions
+8 -8
View File
@@ -45,17 +45,17 @@ body { color: blue }
-- layouts/home.html --
{{ with resources.Get "css/main1.css" }}
{{ with . | css.PostCSS }}
CSS1 size: {{ .Content | len }}|{{ .RelPermalink }}|
CSS1: {{ .RelPermalink }}|{{ gt (.Content | len) 10 }}|
{{ end }}
{{ end }}
{{ with resources.Get "css/main2.css" }}
{{ with resources.Get "css/main2.css" }}
{{ with . | css.TailwindCSS }}
CSS2 size: {{ .Content | len }}|{{ .RelPermalink }}|
CSS2: {{ .RelPermalink }}|{{ gt (.Content | len) 10 }}|
{{ end }}
{{ end }}
{{ with resources.Get "js/main.js" }}
{{ with resources.Get "js/main.js" }}
{{ with . | js.Babel }}
JS size: {{ .Content | len }}|{{ .RelPermalink }}|
JS: {{ .RelPermalink }}|{{ gt (.Content | len) 10 }}|
{{ end }}
{{ end }}
`
@@ -67,8 +67,8 @@ body { color: blue }
))
b.AssertFileContent("public/index.html",
"CSS1 size: 233|/css/main1.css|",
"CSS2 size: 4557|/css/main2.css|",
"JS size: 31|/js/main.js|",
"CSS1: /css/main1.css|true|",
"CSS2: /css/main2.css|true|",
"JS: /js/main.js|true|",
)
}