From 5e7ec5bcb4e5127788f04b1d945de38d4c8093e2 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Thu, 27 Jun 2019 14:04:12 +0300 Subject: [PATCH] fix: hmr should work with uglify Currently `hmr` with `--env.uglify` is not working as the uglifier touches all files. This leads to emit of files that are not hot updates. When CLI finds such files, it decides hmr is not successful and restarts the application. However, some of the emitted files are not actully changed. These emitted (and not changed) files are chunks of the entry points - as we are with HMR if there's an actual change for them, we'll receive hot-update files. Currently there's a logic to skip all emitted entry points and webpack runtime files (`runtime.js`) when we are with HMR. To fix the current issue, extend this logic to skip emitted chunks of entry points as well when we are with HMR and there's no hot-update for them. --- plugins/WatchStateLoggerPlugin.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/WatchStateLoggerPlugin.ts b/plugins/WatchStateLoggerPlugin.ts index bbcff833..e10bca88 100644 --- a/plugins/WatchStateLoggerPlugin.ts +++ b/plugins/WatchStateLoggerPlugin.ts @@ -64,10 +64,9 @@ function getWebpackRuntimeOnlyFiles(compilation) { function getEntryPointFiles(compilation) { const entryPointFiles = []; try { - Array.from(compilation.entrypoints.values()) + Array.from(compilation.entrypoints.values()) .forEach((entrypoint: any) => { - const entryChunk = entrypoint.chunks.find(chunk => chunk.name === entrypoint.options.name); - if (entryChunk) { + for (const entryChunk of entrypoint.chunks) { entryChunk.files.forEach(fileName => { if (fileName.indexOf("hot-update") === -1) { entryPointFiles.push(fileName); @@ -79,5 +78,6 @@ function getEntryPointFiles(compilation) { console.log("Warning: Unable to find Webpack entry point files."); } - return entryPointFiles; + return entryPointFiles + .filter((value, index, self) => self.indexOf(value) === index); // get only the unique files } \ No newline at end of file