Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash when publicPath is function #881

Merged
merged 2 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,22 @@ export function pitch(request) {
return;
}

const isAbsolutePublicPath = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(publicPath);
const publicPathForExtract = isAbsolutePublicPath
? publicPath
: `${ABSOLUTE_PUBLIC_PATH}${publicPath.replace(
/\./g,
SINGLE_DOT_PATH_SEGMENT
)}`;
let publicPathForExtract;

if (typeof publicPath === "string") {
const isAbsolutePublicPath = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(
publicPath
);

publicPathForExtract = isAbsolutePublicPath
? publicPath
: `${ABSOLUTE_PUBLIC_PATH}${publicPath.replace(
/\./g,
SINGLE_DOT_PATH_SEGMENT
)}`;
} else {
publicPathForExtract = publicPath;
}

this.importModule(
`${this.resourcePath}.webpack[javascript/auto]!=!!!${request}`,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
background: green;
background-image: url(http://example.com/XXXX/c9e192c015437a21dea1.svg);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
background: red;
background-image: url(http://example.com/XXXX/c9e192c015437a21dea1.svg);
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
background: green;
background-image: url(http://example.com/4d869bb95ecdf3f870fb/c9e192c015437a21dea1.svg);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
background: red;
background-image: url(http://example.com/ca6e489a6807af3e778c/c9e192c015437a21dea1.svg);
}

4 changes: 4 additions & 0 deletions test/cases/publicpath-function-2/nested/again/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background: green;
background-image: url(../../react.svg);
}
4 changes: 4 additions & 0 deletions test/cases/publicpath-function-2/nested/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background: red;
background-image: url(../react.svg);
}
1 change: 1 addition & 0 deletions test/cases/publicpath-function-2/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions test/cases/publicpath-function-2/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Self from "../../../src";

module.exports = {
entry: {
// Specific CSS entry point, with output to a nested folder
"nested/style": "./nested/style.css",
// Note that relative nesting of output is the same as that of the input
"nested/again/style": "./nested/again/style.css",
},
output: {
// Compute publicPath relative to the CSS output
publicPath: (pathData) => `http://example.com/${pathData.hash}/`,
},
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: Self.loader,
},
"css-loader",
],
},
],
},
plugins: [
new Self({
filename: "[name].css",
}),
],
};