@@ -16,7 +16,15 @@ module.exports.pitch = function(request, preReq, data) {
16
16
this . cacheable && this . cacheable ( ) ;
17
17
var query = loaderUtils . parseQuery ( this . query ) ;
18
18
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 ) ) {
20
28
if ( query . omit ) {
21
29
this . loaderIndex += + query . omit + 1 ;
22
30
request = request . split ( "!" ) . slice ( + query . omit ) . join ( "!" ) ;
@@ -47,6 +55,13 @@ module.exports.pitch = function(request, preReq, data) {
47
55
compilation . cache = compilation . cache [ subCache ] ;
48
56
}
49
57
} ) ;
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
+ } ) ;
50
65
var source ;
51
66
childCompiler . plugin ( "after-compile" , function ( compilation , callback ) {
52
67
source = compilation . assets [ childFilename ] && compilation . assets [ childFilename ] . source ( ) ;
@@ -98,4 +113,4 @@ module.exports.pitch = function(request, preReq, data) {
98
113
return resultSource ;
99
114
}
100
115
}
101
- } ;
116
+ } ;
0 commit comments