From ffa256ddaab4a7b7571711006b8e6cc95eda1144 Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Thu, 1 Aug 2019 17:41:29 +0300 Subject: [PATCH] fix: include all chunkFiles in fallbackFiles in order to avoid wrong lazy Angular chunks --- .../webpack/webpack-compiler-service.ts | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/lib/services/webpack/webpack-compiler-service.ts b/lib/services/webpack/webpack-compiler-service.ts index 6a6fbcb94a..29f6c4c7f8 100644 --- a/lib/services/webpack/webpack-compiler-service.ts +++ b/lib/services/webpack/webpack-compiler-service.ts @@ -221,33 +221,25 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp return args; } - private getUpdatedEmittedFiles(emittedFiles: string[], chunkFiles: string[]) { - let fallbackFiles: string[] = []; + private getUpdatedEmittedFiles(allEmittedFiles: string[], chunkFiles: string[]) { + const hotHash = this.getCurrentHotUpdateHash(allEmittedFiles); + const emittedHotUpdateFiles = _.difference(allEmittedFiles, chunkFiles); + + return { emittedFiles: emittedHotUpdateFiles, fallbackFiles: chunkFiles, hash: hotHash }; + } + + private getCurrentHotUpdateHash(emittedFiles: string[]) { let hotHash; - let result = emittedFiles.slice(); const hotUpdateScripts = emittedFiles.filter(x => x.endsWith('.hot-update.js')); - if (chunkFiles && chunkFiles.length) { - result = result.filter(file => chunkFiles.indexOf(file) === -1); + if (hotUpdateScripts && hotUpdateScripts.length) { + // the hash is the same for each hot update in the current compilation + const hotUpdateName = hotUpdateScripts[0]; + const matcher = /^(.+)\.(.+)\.hot-update/gm; + const matches = matcher.exec(hotUpdateName); + hotHash = matches[2]; } - hotUpdateScripts.forEach(hotUpdateScript => { - const { name, hash } = this.parseHotUpdateChunkName(hotUpdateScript); - hotHash = hash; - // remove bundle/vendor.js files if there's a bundle.XXX.hot-update.js or vendor.XXX.hot-update.js - result = result.filter(file => file !== `${name}.js`); - }); - // if applying of hot update fails, we must fallback to the full files - fallbackFiles = emittedFiles.filter(file => hotUpdateScripts.indexOf(file) === -1); - - return { emittedFiles: result, fallbackFiles, hash: hotHash }; - } - private parseHotUpdateChunkName(name: string) { - const matcher = /^(.+)\.(.+)\.hot-update/gm; - const matches = matcher.exec(name); - return { - name: matches[1] || "", - hash: matches[2] || "", - }; + return hotHash || ""; } private async stopWebpackForPlatform(platform: string) {