From a01aaff9dfce2833eec03273f46ccf72df7f6a79 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Tue, 3 Aug 2021 18:04:34 +0800 Subject: [PATCH 1/2] fix #469: css import relative paths --- internal/resolver/resolver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/resolver/resolver.go b/internal/resolver/resolver.go index c4ddebd1c9..d70a44a3ef 100644 --- a/internal/resolver/resolver.go +++ b/internal/resolver/resolver.go @@ -626,7 +626,7 @@ func (r resolverQuery) resolveWithoutSymlinks(sourceDir string, importPath strin // Check both relative and package paths for CSS URL tokens, with relative // paths taking precedence over package paths to match Webpack behavior. isPackagePath := IsPackagePath(importPath) - checkRelative := !isPackagePath || r.kind == ast.ImportURL + checkRelative := !isPackagePath || r.kind == ast.ImportURL || r.kind == ast.ImportAt checkPackage := isPackagePath if checkRelative { From d66996db27a79e1389eabf9c0f5340b717c20cff Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Tue, 3 Aug 2021 18:05:04 +0800 Subject: [PATCH 2/2] test: add tests --- internal/bundler/bundler_css_test.go | 3 +++ internal/bundler/snapshots/snapshots_css.txt | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/internal/bundler/bundler_css_test.go b/internal/bundler/bundler_css_test.go index 2d32b41e29..46f8997819 100644 --- a/internal/bundler/bundler_css_test.go +++ b/internal/bundler/bundler_css_test.go @@ -472,10 +472,13 @@ func TestPackageURLsInCSS(t *testing.T) { css_suite.expectBundled(t, bundled{ files: map[string]string{ "/entry.css": ` + @import "test.css"; + a { background: url(a/1.png); } b { background: url(b/2.png); } c { background: url(c/3.png); } `, + "/test.css": `.css { color: red }`, "/a/1.png": `a-1`, "/node_modules/b/2.png": `b-2-node_modules`, "/c/3.png": `c-3`, diff --git a/internal/bundler/snapshots/snapshots_css.txt b/internal/bundler/snapshots/snapshots_css.txt index a2a01b1ea1..11d2ae301a 100644 --- a/internal/bundler/snapshots/snapshots_css.txt +++ b/internal/bundler/snapshots/snapshots_css.txt @@ -242,6 +242,11 @@ console.log("b"); ================================================================================ TestPackageURLsInCSS ---------- /out/entry.css ---------- +/* test.css */ +.css { + color: red; +} + /* entry.css */ a { background: url(data:image/png;base64,YS0x);