Skip to content

Commit 6573f76

Browse files
committed
Fix require.toUrl on the Node side
- Fixes #542
1 parent bbc9ea5 commit 6573f76

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

scripts/webpack.general.config.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ module.exports = (options = {}) => ({
2424
test: /\.(j|t)s/,
2525
options: {
2626
multiple: [{
27-
// These will be handled by file-loader. We need the location because
28-
// they are parsed as URIs and will throw errors if not fully formed.
29-
// The !! prefix causes it to ignore other loaders (doesn't work).
27+
// These will be handled by file-loader. Must be a fully formed URI.
28+
// The !! prefix causes it to ignore other loaders.
3029
search: "require\\.toUrl\\(",
31-
replace: "location.protocol + '//' + location.host + location.pathname.replace(/\\/$/,'') + '/' + require('!!file-loader?name=[path][name].[ext]!' + ",
30+
replace: `${
31+
options.node
32+
? "'file://'"
33+
: "location.protocol + '//' + location.host + location.pathname.replace(/\\/$/,'')"
34+
} + '/' + require('!!file-loader?name=[path][name].[ext]!' + `,
3235
flags: "g",
3336
}, {
3437
search: "require\\.__\\$__nodeRequire",

scripts/webpack.node.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
const merge = require("webpack-merge");
22

33
module.exports = (options = {}) => merge(
4-
require("./webpack.general.config")(options), {
4+
require("./webpack.general.config")({
5+
...options,
6+
node: true,
7+
}), {
58
devtool: "none",
69
mode: "production",
710
target: "node",

0 commit comments

Comments
 (0)