Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CSS import relative paths #1494

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/bundler/bundler_css_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
5 changes: 5 additions & 0 deletions internal/bundler/snapshots/snapshots_css.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down