Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit be82ab7

Browse files
fix: ignore the Webpack runtime chunks when sending HMR updates
1 parent ff226b2 commit be82ab7

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

‎lib/compiler.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ exports.runWebpackCompiler = function runWebpackCompiler(config, $projectData, $
8080
return;
8181
}
8282

83-
const result = getUpdatedEmittedFiles(message.emittedFiles);
83+
const result = getUpdatedEmittedFiles(message.emittedFiles,message.webpackRuntimeFiles);
8484

8585
if (hookArgs.hmrData) {
8686
hookArgs.hmrData[platform] = {

‎lib/utils.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function buildEnvData($projectData, platform, env) {
3434
* if yes this is a HMR update and remove all bundle files as we don't need them to be synced,
3535
* but only the update chunks
3636
*/
37-
function getUpdatedEmittedFiles(emittedFiles) {
37+
function getUpdatedEmittedFiles(emittedFiles,webpackRuntimeFiles) {
3838
let fallbackFiles = [];
3939
let hotHash;
4040
if (emittedFiles.some(x => x.endsWith('.hot-update.json'))) {
@@ -45,6 +45,10 @@ function getUpdatedEmittedFiles(emittedFiles) {
4545
hotHash = hash;
4646
// remove bundle/vendor.js files if there's a bundle.XXX.hot-update.js or vendor.XXX.hot-update.js
4747
result = result.filter(file => file !== `${name}.js`);
48+
if (webpackRuntimeFiles && webpackRuntimeFiles.length) {
49+
// remove files containing only the Webpack runtime (e.g. runtime.js)
50+
result = result.filter(file => webpackRuntimeFiles.indexOf(file) === -1);
51+
}
4852
});
4953
//if applying of hot update fails, we must fallback to the full files
5054
fallbackFiles = emittedFiles.filter(file => result.indexOf(file) === -1);

‎plugins/WatchStateLoggerPlugin.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class WatchStateLoggerPlugin {
3131
console.log(messages.compilationComplete);
3232
}
3333

34+
const runtimeOnlyFiles = getWebpackRuntimeOnlyFiles(compilation, compiler);
3435
let emittedFiles = Object
3536
.keys(compilation.assets)
3637
.filter(assetKey => compilation.assets[assetKey].emitted);
@@ -42,7 +43,28 @@ export class WatchStateLoggerPlugin {
4243

4344
process.send && process.send(messages.compilationComplete, error => null);
4445
// Send emitted files so they can be LiveSynced if need be
45-
process.send && process.send({ emittedFiles: emittedFilesFakePaths }, error => null);
46+
process.send && process.send({ emittedFiles: emittedFilesFakePaths,webpackRuntimeFiles: runtimeOnlyFiles }, error => null);
4647
});
4748
}
4849
}
50+
51+
function getWebpackRuntimeOnlyFiles(compilation, compiler) {
52+
let runtimeOnlyFiles = [];
53+
try {
54+
runtimeOnlyFiles = [].concat(...compilation.chunkGroups
55+
// get the chunk group of each entry points (e.g. main.js and inspector-modules.js)
56+
.map(chunkGroup => chunkGroup.runtimeChunk)
57+
// filter embedded runtime chunks (e.g. part of bundle.js or inspector-modules.js)
58+
.filter(runtimeChunk => runtimeChunk.preventIntegration)
59+
.map(runtimeChunk => runtimeChunk.files))
60+
// get only the unique files in case of "single" runtime (e.g. runtime.js)
61+
.filter((value, index, self) => self.indexOf(value) === index)
62+
// convert to absolute paths
63+
.map(fileName => join(compiler.context, fileName));
64+
} catch (e) {
65+
// breaking change in the Webpack API
66+
console.log("Warning: Unable to find Webpack runtime files.");
67+
}
68+
69+
return runtimeOnlyFiles;
70+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /