Skip to content

Commit 0c9fd9a

Browse files
committed
fix: include all chunkFiles in fallbackFiles in order to avoid wrong lazy Angular chunks
1 parent e3bacd5 commit 0c9fd9a

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

lib/services/webpack/webpack-compiler-service.ts

+17-23
Original file line numberDiff line numberDiff line change
@@ -221,33 +221,27 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
221221
return args;
222222
}
223223

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[]) {
226234
let hotHash;
227-
let result = emittedFiles.slice();
228235
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 = /^(.+)\.(.+)\.hot-update/gm;
240+
const matches = matcher.exec(hotUpdateName);
241+
hotHash = matches[2];
231242
}
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-
}
243243

244-
private parseHotUpdateChunkName(name: string) {
245-
const matcher = /^(.+)\.(.+)\.hot-update/gm;
246-
const matches = matcher.exec(name);
247-
return {
248-
name: matches[1] || "",
249-
hash: matches[2] || "",
250-
};
244+
return hotHash || "";
251245
}
252246

253247
private async stopWebpackForPlatform(platform: string) {

0 commit comments

Comments
 (0)