From 8010e4222af392f4b65ac90f22d0a42e32c70c4a Mon Sep 17 00:00:00 2001 From: Jim Edelstein Date: Thu, 26 Oct 2017 15:31:53 -0400 Subject: [PATCH 1/2] Fix issue with absolute paths using loaderUtils.stringifyRequest instead of JSON.stringify --- index.js | 27 ++++++++++++++------------- package.json | 3 ++- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 35f4709..57b9980 100644 --- a/index.js +++ b/index.js @@ -3,18 +3,19 @@ Author Tobias Koppers @sokra */ var path = require("path"); +var loaderUtils = require("loader-utils"); module.exports = function() {}; module.exports.pitch = function(remainingRequest) { - this.cacheable && this.cacheable(); - return "require(" + JSON.stringify("!!" + path.join(__dirname, "addScript.js")) + ")"+ - "(require(" + - JSON.stringify("!!" + require.resolve("raw-loader") + "!" + remainingRequest) + ")" + - (this.debug ? - "+" + - JSON.stringify( - "\n\n// SCRIPT-LOADER FOOTER\n//# sourceURL=script:///" + - encodeURI(remainingRequest.replace(/^!/, "")).replace(/%5C|%2F/g, "/").replace(/\?/, "%3F").replace(/^\//, "") - ) : - "") + - ")"; -}; + this.cacheable && this.cacheable(); + return "require(" + loaderUtils.stringifyRequest(this, "!!" + path.join(__dirname, "addScript.js")) + ")"+ + "(require(" + + loaderUtils.stringifyRequest(this, "!!" + require.resolve("raw-loader") + "!" + remainingRequest) + ")" + + (this.debug ? + "+" + + JSON.stringify( + "\n\n// SCRIPT-LOADER FOOTER\n//# sourceURL=script:///" + + encodeURI(remainingRequest.replace(/^!/, "")).replace(/%5C|%2F/g, "/").replace(/\?/, "%3F").replace(/^\//, "") + ) : + "") + + ")"; +}; diff --git a/package.json b/package.json index 63bd1aa..19b8fd4 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "release": "standard-version" }, "dependencies": { - "raw-loader": "~0.5.1" + "raw-loader": "~0.5.1", + "loader-utils": "~1.1.0" }, "devDependencies": { "standard-version": "^4.2.0" From 74bf028fb1802571ca0816aaa9b1e823194db19a Mon Sep 17 00:00:00 2001 From: Jim Edelstein Date: Tue, 23 Oct 2018 12:19:19 -0400 Subject: [PATCH 2/2] add missing space per comment on PR #49 --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 57b9980..c69248e 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ var loaderUtils = require("loader-utils"); module.exports = function() {}; module.exports.pitch = function(remainingRequest) { this.cacheable && this.cacheable(); - return "require(" + loaderUtils.stringifyRequest(this, "!!" + path.join(__dirname, "addScript.js")) + ")"+ + return "require(" + loaderUtils.stringifyRequest(this, "!!" + path.join(__dirname, "addScript.js")) + ")" + "(require(" + loaderUtils.stringifyRequest(this, "!!" + require.resolve("raw-loader") + "!" + remainingRequest) + ")" + (this.debug ?