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

Commit cea03e2

Browse files
committed
Make plugin re-entrant
This disallows spawning child compilers from a child compiler. Fixes #17.
1 parent 175279f commit cea03e2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

loader.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ 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] === false) {
21+
return "";
22+
} else if(this[__dirname](null, query)) {
2023
if(query.omit) {
2124
this.loaderIndex += +query.omit + 1;
2225
request = request.split("!").slice(+query.omit).join("!");
@@ -47,6 +50,13 @@ module.exports.pitch = function(request, preReq, data) {
4750
compilation.cache = compilation.cache[subCache];
4851
}
4952
});
53+
// We set loaderContext[__dirname] = false to indicate we already in
54+
// a child compiler so we don't spawn another child compilers from there.
55+
childCompiler.plugin("this-compilation", function(compilation) {
56+
compilation.plugin("normal-module-loader", function(loaderContext, module) {
57+
loaderContext[__dirname] = false;
58+
});
59+
});
5060
var source;
5161
childCompiler.plugin("after-compile", function(compilation, callback) {
5262
source = compilation.assets[childFilename] && compilation.assets[childFilename].source();
@@ -98,4 +108,4 @@ module.exports.pitch = function(request, preReq, data) {
98108
return resultSource;
99109
}
100110
}
101-
};
111+
};

0 commit comments

Comments
 (0)