@@ -19,23 +19,33 @@ LoaderPlugin.prototype.apply = function(compiler) {
1919 compilation . plugin ( "normal-module-loader" , function ( loaderContext , module ) {
2020 loaderContext . loadModule = function loadModule ( request , callback ) {
2121 var dep = new LoaderDependency ( request ) ;
22- compilation . addModuleDependencies ( module , [ [ dep ] ] , true , "lm" , false , function ( err , module ) {
22+ compilation . addModuleDependencies ( module , [ [ dep ] ] , true , "lm" , false , function ( err ) {
2323 if ( err ) return callback ( err ) ;
24+
25+ module = dep . module ;
26+ if ( ! module ) return callback ( new Error ( "Cannot load the module" ) ) ;
27+ if ( module . building ) module . building . push ( next ) ;
28+ else next ( ) ;
2429
25- if ( ! dep . module . _source ) throw new Error ( "The module created for a LoaderDependency must have a property _source" ) ;
26- var map = dep . module . _source . map ( ) ;
27- var source = dep . module . _source . source ( ) ;
28- if ( dep . module . fileDependencies ) {
29- dep . module . fileDependencies . forEach ( function ( dep ) {
30- loaderContext . addDependency ( dep ) ;
31- } ) ;
32- }
33- if ( dep . module . contextDependencies ) {
34- dep . module . contextDependencies . forEach ( function ( dep ) {
35- loaderContext . addContextDependency ( dep ) ;
36- } ) ;
30+ function next ( err ) {
31+ if ( err ) return callback ( err ) ;
32+
33+ if ( dep . module . error ) return callback ( dep . module . error ) ;
34+ if ( ! dep . module . _source ) throw new Error ( "The module created for a LoaderDependency must have a property _source" ) ;
35+ var map = dep . module . _source . map ( ) ;
36+ var source = dep . module . _source . source ( ) ;
37+ if ( dep . module . fileDependencies ) {
38+ dep . module . fileDependencies . forEach ( function ( dep ) {
39+ loaderContext . addDependency ( dep ) ;
40+ } ) ;
41+ }
42+ if ( dep . module . contextDependencies ) {
43+ dep . module . contextDependencies . forEach ( function ( dep ) {
44+ loaderContext . addContextDependency ( dep ) ;
45+ } ) ;
46+ }
47+ return callback ( null , source , map , dep . module ) ;
3748 }
38- return callback ( null , source , map , dep . module ) ;
3949 } ) ;
4050 } ;
4151 } ) ;
0 commit comments