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

+16-7
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}`,
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+
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+
Loading
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+
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background: green;
3+
background-image: url(../../react.svg);
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background: red;
3+
background-image: url(../react.svg);
4+
}
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Self from "../../../src";
2+
3+
module.exports = {
4+
entry: {
5+
// Specific CSS entry point, with output to a nested folder
6+
"nested/style": "./nested/style.css",
7+
// Note that relative nesting of output is the same as that of the input
8+
"nested/again/style": "./nested/again/style.css",
9+
},
10+
output: {
11+
// Compute publicPath relative to the CSS output
12+
publicPath: (pathData) => `http://example.com/${pathData.hash}/`,
13+
},
14+
module: {
15+
rules: [
16+
{
17+
test: /\.css$/,
18+
use: [
19+
{
20+
loader: Self.loader,
21+
},
22+
"css-loader",
23+
],
24+
},
25+
],
26+
},
27+
plugins: [
28+
new Self({
29+
filename: "[name].css",
30+
}),
31+
],
32+
};

0 commit comments

Comments
 (0)