From ae87591513c67a4bd337aa20ac6ea6f28e326c2b Mon Sep 17 00:00:00 2001 From: Izaak Schroeder Date: Thu, 6 Oct 2016 22:48:18 -0700 Subject: [PATCH 1/2] Pass proper loader `options` to children. Using just the serialized request means that query objects (that is to say, those which are not strings), get munged if they have anything non-serializable in them. This means passing data to `postcss` via `query` is impossible. To remedy this, we detect when the original request is being processed and apply the original loader transformations instead of whatever came through the serialized version. --- loader.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/loader.js b/loader.js index e5ab1da1..4960135f 100644 --- a/loader.js +++ b/loader.js @@ -20,6 +20,7 @@ module.exports = function(source) { module.exports.pitch = function(request) { if(this.cacheable) this.cacheable(); var query = loaderUtils.parseQuery(this.query); + var loaders = this.loaders.slice(this.loaderIndex + 1); this.addDependency(this.resourcePath); // We already in child compiler, return empty bundle if(this[NS] === undefined) { @@ -33,6 +34,7 @@ module.exports.pitch = function(request) { if(query.omit) { this.loaderIndex += +query.omit + 1; request = request.split("!").slice(+query.omit).join("!"); + loaders = loaders.slice(+query.omit); } var resultSource; if(query.remove) { @@ -64,10 +66,19 @@ module.exports.pitch = function(request) { // We set loaderContext[NS] = false to indicate we already in // a child compiler so we don't spawn another child compilers from there. childCompiler.plugin("this-compilation", function(compilation) { - compilation.plugin("normal-module-loader", function(loaderContext) { + compilation.plugin("normal-module-loader", function(loaderContext, module) { loaderContext[NS] = false; + if (module.request === request) { + module.loaders = loaders.map(function(loader) { + return { + loader: loader.path, + options: loader.options + }; + }); + } }); }); + var source; childCompiler.plugin("after-compile", function(compilation, callback) { source = compilation.assets[childFilename] && compilation.assets[childFilename].source(); From 97a6281d7b61de0845d0a8d712938526d55219b2 Mon Sep 17 00:00:00 2001 From: Izaak Schroeder Date: Thu, 6 Oct 2016 23:41:24 -0700 Subject: [PATCH 2/2] Update `loader-utils` to latest. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 65e5db14..ee460742 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "dependencies": { "async": "^1.5.0", - "loader-utils": "^0.2.3", + "loader-utils": "^0.2.16", "webpack-sources": "^0.1.0" }, "devDependencies": {