Skip to content

Commit 6abf42d

Browse files
izaakschroederjoshwiens
authored andcommitted
fix(options): pass proper loader options to children (faceyspacey#266)
* 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. * Update `loader-utils` to latest.
1 parent 5b29f9a commit 6abf42d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

loader.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = function(source) {
2020
module.exports.pitch = function(request) {
2121
if(this.cacheable) this.cacheable();
2222
var query = loaderUtils.parseQuery(this.query);
23+
var loaders = this.loaders.slice(this.loaderIndex + 1);
2324
this.addDependency(this.resourcePath);
2425
// We already in child compiler, return empty bundle
2526
if(this[NS] === undefined) {
@@ -33,6 +34,7 @@ module.exports.pitch = function(request) {
3334
if(query.omit) {
3435
this.loaderIndex += +query.omit + 1;
3536
request = request.split("!").slice(+query.omit).join("!");
37+
loaders = loaders.slice(+query.omit);
3638
}
3739
var resultSource;
3840
if(query.remove) {
@@ -64,10 +66,19 @@ module.exports.pitch = function(request) {
6466
// We set loaderContext[NS] = false to indicate we already in
6567
// a child compiler so we don't spawn another child compilers from there.
6668
childCompiler.plugin("this-compilation", function(compilation) {
67-
compilation.plugin("normal-module-loader", function(loaderContext) {
69+
compilation.plugin("normal-module-loader", function(loaderContext, module) {
6870
loaderContext[NS] = false;
71+
if (module.request === request) {
72+
module.loaders = loaders.map(function(loader) {
73+
return {
74+
loader: loader.path,
75+
options: loader.options
76+
};
77+
});
78+
}
6979
});
7080
});
81+
7182
var source;
7283
childCompiler.plugin("after-compile", function(compilation, callback) {
7384
source = compilation.assets[childFilename] && compilation.assets[childFilename].source();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"dependencies": {
1313
"async": "^2.1.2",
14-
"loader-utils": "^0.2.3",
14+
"loader-utils": "^0.2.16",
1515
"webpack-sources": "^0.1.0"
1616
},
1717
"devDependencies": {

0 commit comments

Comments
 (0)