Skip to content

Commit 9e52d26

Browse files
fix: don't break loader on invalid or not exists url or import token (#827)
1 parent 255c0f0 commit 9e52d26

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

lib/loader.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ module.exports = function loader(content, map) {
130130
// Prepare replacer to change from `___CSS_LOADER_IMPORT___INDEX___` to `require('./file.css').locals`
131131
const importItemReplacer = (item) => {
132132
const match = placholderRegExps.importItem.exec(item);
133-
const idx = +match[1];
133+
const idx = Number(match[1]);
134+
135+
if (!importItems[idx]) {
136+
return item;
137+
}
138+
134139
const importItem = importItems[idx];
135140
const importUrl = importUrlPrefix + importItem.url;
136141

@@ -208,7 +213,12 @@ module.exports = function loader(content, map) {
208213
placholderRegExps.urlItemG,
209214
(item) => {
210215
const match = placholderRegExps.urlItem.exec(item);
211-
let idx = +match[1];
216+
let idx = Number(match[1]);
217+
218+
if (!urlItems[idx]) {
219+
return item;
220+
}
221+
212222
const urlItem = urlItems[idx];
213223
const { url } = urlItem;
214224

0 commit comments

Comments
 (0)