Skip to content

Commit 0c47cf7

Browse files
authoredMar 10, 2021
fix: handling @import with spaces and any extensions (#1272)
1 parent 3f49ed0 commit 0c47cf7

File tree

5 files changed

+109
-12
lines changed

5 files changed

+109
-12
lines changed
 

‎src/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export default async function loader(content, map, meta) {
6666
extensions: [".css"],
6767
mainFields: ["css", "style", "main", "..."],
6868
mainFiles: ["index", "..."],
69-
restrictions: [/\.css$/i],
7069
});
7170

7271
plugins.push(

‎src/utils.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ function defaultGetLocalIdent(
7979
}
8080

8181
function normalizeUrl(url, isStringValue) {
82-
let normalizedUrl = url;
82+
let normalizedUrl = url
83+
.replace(/^( |\t\n|\r\n|\r|\f)*/g, "")
84+
.replace(/( |\t\n|\r\n|\r|\f)*$/g, "");
8385

8486
if (isStringValue && /\\(\n|\r\n|\r|\f)/.test(normalizedUrl)) {
8587
normalizedUrl = normalizedUrl.replace(/\\(\n|\r\n|\r|\f)/g, "");

‎test/__snapshots__/import-option.test.js.snap

+97-10
Large diffs are not rendered by default.

‎test/fixtures/import/import.css

+6
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,9 @@ st.css');
143143

144144
@import url('something.css?foo=1&bar=2');
145145
@import url('something.css?foo=2&bar=1');
146+
147+
@import " ./test.css ";
148+
@import url(' ./test.css ');
149+
@import url( ./test.css );
150+
151+
@import "./my.scss";

‎test/fixtures/import/my.scss

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a {
2+
color: red;
3+
}

0 commit comments

Comments
 (0)
Please sign in to comment.