Skip to content

Commit 1d05dae

Browse files
authored
Merge pull request #4689 from NativeScript/fatme/hot-update-files
fix: emit only `bundle.<hash>.hot-update.js` and `<hash>.hot-update.json` files when `--hmr` is provided
2 parents abc74f1 + 013817b commit 1d05dae

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
3737
return;
3838
}
3939

40-
const result = this.getUpdatedEmittedFiles(message.emittedFiles, message.webpackRuntimeFiles);
40+
const result = this.getUpdatedEmittedFiles(message.emittedFiles, message.webpackRuntimeFiles, message.entryPointFiles);
4141

4242
const files = result.emittedFiles
43-
.filter((file: string) => file.indexOf("App_Resources") === -1)
4443
.map((file: string) => path.join(platformData.appDestinationDirectoryPath, "app", file));
4544

4645
const data = {
@@ -178,23 +177,25 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
178177
return args;
179178
}
180179

181-
private getUpdatedEmittedFiles(emittedFiles: string[], webpackRuntimeFiles: string[]) {
180+
private getUpdatedEmittedFiles(emittedFiles: string[], webpackRuntimeFiles: string[], entryPointFiles: string[]) {
182181
let fallbackFiles: string[] = [];
183182
let hotHash;
184183
if (emittedFiles.some(x => x.endsWith('.hot-update.json'))) {
185184
let result = emittedFiles.slice();
186185
const hotUpdateScripts = emittedFiles.filter(x => x.endsWith('.hot-update.js'));
186+
if (webpackRuntimeFiles && webpackRuntimeFiles.length) {
187+
result = result.filter(file => webpackRuntimeFiles.indexOf(file) === -1);
188+
}
189+
if (entryPointFiles && entryPointFiles.length) {
190+
result = result.filter(file => entryPointFiles.indexOf(file) === -1);
191+
}
187192
hotUpdateScripts.forEach(hotUpdateScript => {
188193
const { name, hash } = this.parseHotUpdateChunkName(hotUpdateScript);
189194
hotHash = hash;
190195
// remove bundle/vendor.js files if there's a bundle.XXX.hot-update.js or vendor.XXX.hot-update.js
191196
result = result.filter(file => file !== `${name}.js`);
192-
if (webpackRuntimeFiles && webpackRuntimeFiles.length) {
193-
// remove files containing only the Webpack runtime (e.g. runtime.js)
194-
result = result.filter(file => webpackRuntimeFiles.indexOf(file) === -1);
195-
}
196197
});
197-
//if applying of hot update fails, we must fallback to the full files
198+
// if applying of hot update fails, we must fallback to the full files
198199
fallbackFiles = emittedFiles.filter(file => result.indexOf(file) === -1);
199200
return { emittedFiles: result, fallbackFiles, hash: hotHash };
200201
}

0 commit comments

Comments
 (0)