From 4aa20fd8649729b4dbbd427b8bcbd9e99a9ade44 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 19 Apr 2019 13:31:34 -0500 Subject: [PATCH] Fix require.toUrl on the Node side - Fixes #542 --- scripts/webpack.general.config.js | 11 +++++++---- scripts/webpack.node.config.js | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/webpack.general.config.js b/scripts/webpack.general.config.js index d855dc81..02addc21 100644 --- a/scripts/webpack.general.config.js +++ b/scripts/webpack.general.config.js @@ -24,11 +24,14 @@ module.exports = (options = {}) => ({ test: /\.(j|t)s/, options: { multiple: [{ - // These will be handled by file-loader. We need the location because - // they are parsed as URIs and will throw errors if not fully formed. - // The !! prefix causes it to ignore other loaders (doesn't work). + // These will be handled by file-loader. Must be a fully formed URI. + // The !! prefix causes it to ignore other loaders. search: "require\\.toUrl\\(", - replace: "location.protocol + '//' + location.host + location.pathname.replace(/\\/$/,'') + '/' + require('!!file-loader?name=[path][name].[ext]!' + ", + replace: `${ + options.node + ? "'file://'" + : "location.protocol + '//' + location.host + location.pathname.replace(/\\/$/,'')" + } + '/' + require('!!file-loader?name=[path][name].[ext]!' + `, flags: "g", }, { search: "require\\.__\\$__nodeRequire", diff --git a/scripts/webpack.node.config.js b/scripts/webpack.node.config.js index 96160430..559321aa 100644 --- a/scripts/webpack.node.config.js +++ b/scripts/webpack.node.config.js @@ -1,7 +1,10 @@ const merge = require("webpack-merge"); module.exports = (options = {}) => merge( - require("./webpack.general.config")(options), { + require("./webpack.general.config")({ + ...options, + node: true, + }), { devtool: "none", mode: "production", target: "node",