@@ -17,7 +17,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
1717 var hotUpdateMainFilename = compiler . options . output . hotUpdateMainFilename ;
1818 compiler . plugin ( "compilation" , function ( compilation , params ) {
1919 var hotUpdateChunkTemplate = compilation . compiler . hotUpdateChunkTemplate ;
20- if ( ! hotUpdateChunkTemplate && ! compilation . mainTemplate . renderHotModuleReplacementInit ) return ;
20+ if ( ! hotUpdateChunkTemplate ) return ;
2121
2222 var normalModuleFactory = params . normalModuleFactory ;
2323 var contextModuleFactory = params . contextModuleFactory ;
@@ -107,41 +107,43 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
107107 var mainTemplate = compilation . mainTemplate ;
108108 compilation . mainTemplate = Object . create ( mainTemplate ) ;
109109
110- compilation . mainTemplate . updateHash = function ( hash ) {
110+ compilation . mainTemplate . plugin ( "hash" , function ( hash ) {
111111 hash . update ( "HotMainTemplateDecorator" ) ;
112- mainTemplate . updateHash ( hash ) ;
113- } ;
112+ } ) ;
114113
115- compilation . mainTemplate . renderRequireFunctionForModule = function ( hash , chunk , varModuleId ) {
114+ compilation . mainTemplate . plugin ( "module-require" , function ( _ , chunk , hash , varModuleId ) {
116115 return "hotCreateRequire(" + varModuleId + ")" ;
117- } ;
116+ } ) ;
118117
119- compilation . mainTemplate . renderInit = function ( hash , chunk ) {
120- var buf = mainTemplate . renderInit ( hash , chunk ) ;
121- buf = buf . concat ( this . renderHotModuleReplacementInit ( hash , chunk ) ) ;
122- buf . push ( "\n\n" ) ;
123- buf . push ( hotInitCode
124- . replace ( / \$ r e q u i r e \$ / g, this . requireFn )
125- . replace ( / \$ h a s h \$ / g, JSON . stringify ( hash ) )
126- . replace ( / \/ \* f o r e a c h I n s t a l l e d C h u n k s \* \/ / g, chunk . chunks . length > 0 ? "for(var chunkId in installedChunks)" : "var chunkId = 0;" ) ) ;
127- return buf ;
128- } ;
118+ compilation . mainTemplate . plugin ( "bootstrap" , function ( source , chunk , hash ) {
119+ source = this . applyPluginsWaterfall ( "hot-bootstrap" , source , chunk , hash ) ;
120+ return this . asString ( [
121+ source ,
122+ "" ,
123+ hotInitCode
124+ . replace ( / \$ r e q u i r e \$ / g, this . requireFn )
125+ . replace ( / \$ h a s h \$ / g, JSON . stringify ( hash ) )
126+ . replace ( / \/ \* f o r e a c h I n s t a l l e d C h u n k s \* \/ / g, chunk . chunks . length > 0 ? "for(var chunkId in installedChunks)" : "var chunkId = 0;" )
127+ ] ) ;
128+ } ) ;
129129
130- compilation . mainTemplate . useChunkHash = false ;
130+ compilation . mainTemplate . plugin ( "global-hash" , function ( ) {
131+ return true ;
132+ } ) ;
131133
132- compilation . mainTemplate . renderCurrentHashCode = function ( hash ) {
134+ compilation . mainTemplate . plugin ( "current-hash" , function ( ) {
133135 return "hotCurrentHash" ;
134- } ;
136+ } ) ;
135137
136- compilation . mainTemplate . renderModule = function ( hash , chunk , varModuleId ) {
137- var buf = mainTemplate . renderModule ( hash , chunk , varModuleId ) ;
138- buf . push ( buf . pop ( ) + "," ) ;
139- buf . push ( "hot: hotCreateModule(" + varModuleId + ")," ) ;
140- buf . push ( "parents: [hotCurrentParent]," ) ;
141- buf . push ( "data: hotCurrentModuleData[" + varModuleId + "]," ) ;
142- buf . push ( "children: []" ) ;
143- return buf ;
144- } ;
138+ compilation . mainTemplate . plugin ( "module-obj" , function ( source , chunk , hash , varModuleId ) {
139+ return this . asString ( [
140+ source + "," ,
141+ "hot: hotCreateModule(" + varModuleId + ")," ,
142+ "parents: [hotCurrentParent]," ,
143+ "data: hotCurrentModuleData[" + varModuleId + "]," ,
144+ "children: []"
145+ ] ) ;
146+ } ) ;
145147
146148 } ) ;
147149 compiler . parser . plugin ( "evaluate Identifier module.hot" , function ( expr ) {
0 commit comments