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

Commit f7baae6

Browse files
committed
Merge pull request #18 from andreypopp/master
Make plugin re-entrant
2 parents 175279f + 8cdda4a commit f7baae6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

loader.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ module.exports.pitch = function(request, preReq, data) {
1616
this.cacheable && this.cacheable();
1717
var query = loaderUtils.parseQuery(this.query);
1818
this.addDependency(this.resourcePath);
19-
if(this[__dirname](null, query)) {
19+
// We already in child compiler, return empty bundle
20+
if(this[__dirname] === undefined) {
21+
throw new Error(
22+
'"extract-text-webpack-plugin" loader is used without the corresponding plugin, ' +
23+
'refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example'
24+
);
25+
} else if(this[__dirname] === false) {
26+
return "";
27+
} else if(this[__dirname](null, query)) {
2028
if(query.omit) {
2129
this.loaderIndex += +query.omit + 1;
2230
request = request.split("!").slice(+query.omit).join("!");
@@ -47,6 +55,13 @@ module.exports.pitch = function(request, preReq, data) {
4755
compilation.cache = compilation.cache[subCache];
4856
}
4957
});
58+
// We set loaderContext[__dirname] = false to indicate we already in
59+
// a child compiler so we don't spawn another child compilers from there.
60+
childCompiler.plugin("this-compilation", function(compilation) {
61+
compilation.plugin("normal-module-loader", function(loaderContext, module) {
62+
loaderContext[__dirname] = false;
63+
});
64+
});
5065
var source;
5166
childCompiler.plugin("after-compile", function(compilation, callback) {
5267
source = compilation.assets[childFilename] && compilation.assets[childFilename].source();
@@ -98,4 +113,4 @@ module.exports.pitch = function(request, preReq, data) {
98113
return resultSource;
99114
}
100115
}
101-
};
116+
};

0 commit comments

Comments
 (0)