Skip to content

Commit 41bd828

Browse files
fix: crash when publicPath is function (#881)
1 parent 0651fa5 commit 41bd828

File tree

11 files changed

+79
-7
lines changed

11 files changed

+79
-7
lines changed

src/loader.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,22 @@ export function pitch(request) {
204204
return;
205205
}
206206

207-
const isAbsolutePublicPath = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(publicPath);
208-
const publicPathForExtract = isAbsolutePublicPath
209-
? publicPath
210-
: `${ABSOLUTE_PUBLIC_PATH}${publicPath.replace(
211-
/\./g,
212-
SINGLE_DOT_PATH_SEGMENT
213-
)}`;
207+
let publicPathForExtract;
208+
209+
if (typeof publicPath === "string") {
210+
const isAbsolutePublicPath = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(
211+
publicPath
212+
);
213+
214+
publicPathForExtract = isAbsolutePublicPath
215+
? publicPath
216+
: `${ABSOLUTE_PUBLIC_PATH}${publicPath.replace(
217+
/\./g,
218+
SINGLE_DOT_PATH_SEGMENT
219+
)}`;
220+
} else {
221+
publicPathForExtract = publicPath;
222+
}
214223

215224
this.importModule(
216225
`${this.resourcePath}.webpack[javascript/auto]!=!!!${request}`,
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
body {
2+
background: green;
3+
background-image: url(http://example.com/XXXX/c9e192c015437a21dea1.svg);
4+
}
5+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
body {
2+
background: red;
3+
background-image: url(http://example.com/XXXX/c9e192c015437a21dea1.svg);
4+
}
5+
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
body {
2+
background: green;
3+
background-image: url(http://example.com/4d869bb95ecdf3f870fb/c9e192c015437a21dea1.svg);
4+
}
5+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
body {
2+
background: red;
3+
background-image: url(http://example.com/ca6e489a6807af3e778c/c9e192c015437a21dea1.svg);
4+
}
5+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background: green;
3+
background-image: url(../../react.svg);
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background: red;
3+
background-image: url(../react.svg);
4+
}
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)