@@ -10,11 +10,14 @@ var RawSource = require("webpack-core/lib/RawSource");
1010var ConstDependency = require ( "./dependencies/ConstDependency" ) ;
1111var NullFactory = require ( "./NullFactory" ) ;
1212
13- function HotModuleReplacementPlugin ( ) {
13+ function HotModuleReplacementPlugin ( options ) {
14+ options = options || { } ;
15+ this . multiStep = options . multiStep ;
1416}
1517module . exports = HotModuleReplacementPlugin ;
1618
1719HotModuleReplacementPlugin . prototype . apply = function ( compiler ) {
20+ var multiStep = this . multiStep ;
1821 var hotUpdateChunkFilename = compiler . options . output . hotUpdateChunkFilename ;
1922 var hotUpdateMainFilename = compiler . options . output . hotUpdateMainFilename ;
2023 compiler . plugin ( "compilation" , function ( compilation , params ) {
@@ -52,20 +55,33 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
5255 records . chunkModuleIds [ chunk . id ] = chunk . modules . map ( function ( m ) { return m . id ; } ) ;
5356 } ) ;
5457 } ) ;
58+ var initialPass = false ;
59+ var recompilation = false ;
5560 compilation . plugin ( "after-hash" , function ( ) {
5661 var records = this . records ;
57- if ( ! records ) return ;
62+ if ( ! records ) return initialPass = true ;
63+ if ( ! records . hash )
64+ initialPass = true ;
5865 var lastHash = records . hash || "x" ;
5966 var preHash = records . preHash || "x" ;
6067 var prepreHash = records . prepreHash || "x" ;
6168 if ( preHash === this . hash ) {
69+ recompilation = true ;
6270 this . modifyHash ( prepreHash ) ;
6371 return ;
6472 }
6573 records . prepreHash = records . hash || "x" ;
6674 records . preHash = this . hash ;
6775 this . modifyHash ( records . prepreHash ) ;
6876 } ) ;
77+ compilation . plugin ( "should-generate-chunk-assets" , function ( ) {
78+ if ( multiStep && ! recompilation && ! initialPass )
79+ return false ;
80+ } ) ;
81+ compilation . plugin ( "need-additional-pass" , function ( ) {
82+ if ( multiStep && ! recompilation && ! initialPass )
83+ return true ;
84+ } ) ;
6985 compilation . plugin ( "additional-chunk-assets" , function ( ) {
7086 var records = this . records ;
7187 if ( records . hash === this . hash ) return ;
@@ -184,7 +200,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
184200 params = [ arg ] ;
185201 }
186202 if ( arg . isArray ( ) ) {
187- params = arg . items . filter ( function ( param ) {
203+ params = arg . items . filter ( function ( param ) {
188204 return param . isString ( ) ;
189205 } ) ;
190206 }
@@ -437,11 +453,11 @@ var hotInitCode = Template.getFunctionContent(function() {
437453 options = { } ;
438454 callback = callback || function ( err ) { if ( err ) throw err } ;
439455 }
440-
456+
441457 function getAffectedStuff ( module ) {
442458 var outdatedModules = [ module ] ;
443459 var outdatedDependencies = { } ;
444-
460+
445461 var queue = outdatedModules . slice ( ) ;
446462 while ( queue . length > 0 ) {
447463 var moduleId = queue . pop ( ) ;
@@ -472,7 +488,7 @@ var hotInitCode = Template.getFunctionContent(function() {
472488 queue . push ( parentId ) ;
473489 }
474490 }
475-
491+
476492 return [ outdatedModules , outdatedDependencies ] ;
477493 }
478494 function addAllToSet ( a , b ) {
0 commit comments