@@ -221,33 +221,27 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
221
221
return args ;
222
222
}
223
223
224
- private getUpdatedEmittedFiles ( emittedFiles : string [ ] , chunkFiles : string [ ] ) {
225
- let fallbackFiles : string [ ] = [ ] ;
224
+ private getUpdatedEmittedFiles ( allEmittedFiles : string [ ] , chunkFiles : string [ ] ) {
225
+ const hotHash = this . getCurrentHotUpdateHash ( allEmittedFiles ) ;
226
+ const emittedHotUpdateFiles = _ . difference ( allEmittedFiles , chunkFiles ) ;
227
+ console . log ( "emittedFiles: " , emittedHotUpdateFiles ) ;
228
+ console . log ( "fallbackFiles: " , chunkFiles ) ;
229
+ console . log ( "hash: " , hotHash ) ;
230
+ return { emittedFiles : emittedHotUpdateFiles , fallbackFiles : chunkFiles , hash : hotHash } ;
231
+ }
232
+
233
+ private getCurrentHotUpdateHash ( emittedFiles : string [ ] ) {
226
234
let hotHash ;
227
- let result = emittedFiles . slice ( ) ;
228
235
const hotUpdateScripts = emittedFiles . filter ( x => x . endsWith ( '.hot-update.js' ) ) ;
229
- if ( chunkFiles && chunkFiles . length ) {
230
- result = result . filter ( file => chunkFiles . indexOf ( file ) === - 1 ) ;
236
+ if ( hotUpdateScripts && hotUpdateScripts . length ) {
237
+ // the hash is the same for each hot update in the current compilation
238
+ const hotUpdateName = hotUpdateScripts [ 0 ] ;
239
+ const matcher = / ^ ( .+ ) \. ( .+ ) \. h o t - u p d a t e / gm;
240
+ const matches = matcher . exec ( hotUpdateName ) ;
241
+ hotHash = matches [ 2 ] ;
231
242
}
232
- hotUpdateScripts . forEach ( hotUpdateScript => {
233
- const { name, hash } = this . parseHotUpdateChunkName ( hotUpdateScript ) ;
234
- hotHash = hash ;
235
- // remove bundle/vendor.js files if there's a bundle.XXX.hot-update.js or vendor.XXX.hot-update.js
236
- result = result . filter ( file => file !== `${ name } .js` ) ;
237
- } ) ;
238
- // if applying of hot update fails, we must fallback to the full files
239
- fallbackFiles = emittedFiles . filter ( file => hotUpdateScripts . indexOf ( file ) === - 1 ) ;
240
-
241
- return { emittedFiles : result , fallbackFiles, hash : hotHash } ;
242
- }
243
243
244
- private parseHotUpdateChunkName ( name : string ) {
245
- const matcher = / ^ ( .+ ) \. ( .+ ) \. h o t - u p d a t e / gm;
246
- const matches = matcher . exec ( name ) ;
247
- return {
248
- name : matches [ 1 ] || "" ,
249
- hash : matches [ 2 ] || "" ,
250
- } ;
244
+ return hotHash || "" ;
251
245
}
252
246
253
247
private async stopWebpackForPlatform ( platform : string ) {
0 commit comments