Skip to content

Commit

Permalink
fix css import url resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Sep 8, 2020
1 parent 9583ded commit 2966ec4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions snowpack/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ class FileBuilder {
return spec;
}
// Handle normal "./" & "../" import specifiers
const extName = path.extname(resolvedImportUrl);
const isProxyImport = extName && extName !== '.js';
const importExtName = path.extname(resolvedImportUrl);
const isProxyImport =
importExtName &&
(file.baseExt === '.js' || file.baseExt === '.html') &&
importExtName !== '.js';
const isAbsoluteUrlPath = path.posix.isAbsolute(resolvedImportUrl);
let resolvedImportPath = removeLeadingSlash(path.normalize(resolvedImportUrl));
// We treat ".proxy.js" files special: we need to make sure that they exist on disk
Expand Down
6 changes: 5 additions & 1 deletion snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,11 @@ export async function command(commandOptions: CommandOptions) {
}
// Support proxy file imports
const extName = path.extname(resolvedImportUrl);
if (extName && extName !== '.js') {
if (
extName &&
(responseExt === '.js' || responseExt === '.html') &&
extName !== '.js'
) {
return resolvedImportUrl + '.proxy.js';
}
return resolvedImportUrl;
Expand Down
2 changes: 1 addition & 1 deletion snowpack/src/rewrite-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function transformCssImports(code: string, replaceImport: (specifier: stri
// Only transform a script element if it contains inlined code / is not empty.
rewrittenCode = spliceString(
rewrittenCode,
`@import "${replaceImport(spec)}"`,
`@import "${replaceImport(spec)}";`,
match.index,
match.index + fullMatch.length,
);
Expand Down
6 changes: 3 additions & 3 deletions test/build/__snapshots__/build.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6357,13 +6357,13 @@ export default 'Button';"

exports[`snowpack build resolve-imports: _dist_/components/style.css 1`] = `
"/* Include 2+ imports to make sure regex isn't borked. */
@import \\"../../TEST_WMU/css-package-a/style.css.proxy.js\\"
@import \\"../../TEST_WMU/@css/package-b/style.css.proxy.js\\""
@import \\"../../TEST_WMU/css-package-a/style.css\\";
@import \\"../../TEST_WMU/@css/package-b/style.css\\";"
`;

exports[`snowpack build resolve-imports: _dist_/components/style.css.proxy.js 1`] = `
"
const code = \\"/* Include 2+ imports to make sure regex isn't borked. */@import \\\\\\"../../TEST_WMU/css-package-a/style.css.proxy.js\\\\\\"@import \\\\\\"../../TEST_WMU/@css/package-b/style.css.proxy.js\\\\\\"\\";
const code = \\"/* Include 2+ imports to make sure regex isn't borked. */@import \\\\\\"../../TEST_WMU/css-package-a/style.css\\\\\\";@import \\\\\\"../../TEST_WMU/@css/package-b/style.css\\\\\\";\\";
const styleEl = document.createElement(\\"style\\");
const codeEl = document.createTextNode(code);
styleEl.type = 'text/css';
Expand Down

0 comments on commit 2966ec4

Please sign in to comment.