Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(options): pass proper loader options to children (#266)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
izaakschroeder authored and joshwiens committed Jan 28, 2017
1 parent 5b29f9a commit 6abf42d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"async": "^2.1.2",
"loader-utils": "^0.2.3",
"loader-utils": "^0.2.16",
"webpack-sources": "^0.1.0"
},
"devDependencies": {
Expand Down

0 comments on commit 6abf42d

Please sign in to comment.