From 2ed8f2604b260064066efaa00510ea5693a76e54 Mon Sep 17 00:00:00 2001 From: fatme Date: Sun, 30 Jun 2019 23:31:06 +0300 Subject: [PATCH] fix: don't restart application when lazy loaded code is changed in angular app with uglify option Currently CLI has a logic to restart the application when one or more of the emitted files from webpack compilation is not hot update. When a lazy loaded code is changed in angular application and uglify option is provided, CLI always restarts the application. (as 0.js, 1.js are reported as changed). This happens due to the fact that CLI omits entry point files and runtime files from emitted files to check if all rest files are hot updates. As the lazy loaded chunks (`0.js`, `1.js`) are neither entry point files nor runtime files, they are not omitted and CLI decides that there is file that is not hot update and restarts the application. This PR changes this behavior and respects only chunk files from webpack compilation. Chunk files are all files except hot update files. Chunk files are: `runtime.js`, `tns_modules/inspector-modules.js`, `bundle.js`, `vendor.js` and all lazy loaded modules. --- lib/services/webpack/webpack-compiler-service.ts | 11 ++++------- lib/services/webpack/webpack.d.ts | 3 +-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/services/webpack/webpack-compiler-service.ts b/lib/services/webpack/webpack-compiler-service.ts index d238bcc7a8..f795aaa72d 100644 --- a/lib/services/webpack/webpack-compiler-service.ts +++ b/lib/services/webpack/webpack-compiler-service.ts @@ -45,7 +45,7 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp let result; if (prepareData.hmr) { - result = this.getUpdatedEmittedFiles(message.emittedFiles, message.webpackRuntimeFiles, message.entryPointFiles); + result = this.getUpdatedEmittedFiles(message.emittedFiles, message.chunkFiles); } else { result = { emittedFiles: message.emittedFiles, fallbackFiles: [], hash: "" }; } @@ -218,16 +218,13 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp return args; } - private getUpdatedEmittedFiles(emittedFiles: string[], webpackRuntimeFiles: string[], entryPointFiles: string[]) { + private getUpdatedEmittedFiles(emittedFiles: string[], chunkFiles: string[]) { let fallbackFiles: string[] = []; let hotHash; let result = emittedFiles.slice(); const hotUpdateScripts = emittedFiles.filter(x => x.endsWith('.hot-update.js')); - if (webpackRuntimeFiles && webpackRuntimeFiles.length) { - result = result.filter(file => webpackRuntimeFiles.indexOf(file) === -1); - } - if (entryPointFiles && entryPointFiles.length) { - result = result.filter(file => entryPointFiles.indexOf(file) === -1); + if (chunkFiles && chunkFiles.length) { + result = result.filter(file => chunkFiles.indexOf(file) === -1); } hotUpdateScripts.forEach(hotUpdateScript => { const { name, hash } = this.parseHotUpdateChunkName(hotUpdateScript); diff --git a/lib/services/webpack/webpack.d.ts b/lib/services/webpack/webpack.d.ts index 7f03b1b3c4..9f1b68e977 100644 --- a/lib/services/webpack/webpack.d.ts +++ b/lib/services/webpack/webpack.d.ts @@ -34,8 +34,7 @@ declare global { interface IWebpackEmitMessage { emittedFiles: string[]; - webpackRuntimeFiles: string[]; - entryPointFiles: string[]; + chunkFiles: string[]; } interface IPlatformProjectService extends NodeJS.EventEmitter, IPlatformProjectServiceBase {