Skip to content

Commit 17ebfb9

Browse files
committed
webpack-hot-client seem to call `addEntry` multiple which causes two Entrypoints with the same name This lead the bad side effects i. e. optimization.runtimeChunk no longer works correctly Now adding an entry with the same name replaces the existing entry
1 parent 5539f57 commit 17ebfb9

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

lib/Compilation.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ class Compilation extends Tapable {
10251025
addEntry(context, entry, name, callback) {
10261026
const slot = {
10271027
name: name,
1028+
// TODO webpack 5 remove `request`
10281029
request: null,
10291030
module: null
10301031
};
@@ -1033,7 +1034,14 @@ class Compilation extends Tapable {
10331034
slot.request = entry.request;
10341035
}
10351036

1036-
this._preparedEntrypoints.push(slot);
1037+
// TODO webpack 5: merge modules instead when multiple entry modules are supported
1038+
const idx = this._preparedEntrypoints.findIndex(slot => slot.name === name);
1039+
if (idx >= 0) {
1040+
// Overwrite existing entrypoint
1041+
this._preparedEntrypoints[idx] = slot;
1042+
} else {
1043+
this._preparedEntrypoints.push(slot);
1044+
}
10371045
this._addModuleChain(
10381046
context,
10391047
entry,
@@ -1049,7 +1057,9 @@ class Compilation extends Tapable {
10491057
slot.module = module;
10501058
} else {
10511059
const idx = this._preparedEntrypoints.indexOf(slot);
1052-
this._preparedEntrypoints.splice(idx, 1);
1060+
if (idx >= 0) {
1061+
this._preparedEntrypoints.splice(idx, 1);
1062+
}
10531063
}
10541064
return callback(null, module);
10551065
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("should load correct entry", function() {
2+
throw new Error("This entrypoint should not be used");
3+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("should load correct entry", function() {
2+
// ok
3+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
findBundle: function() {
3+
return [
4+
"./runtime~main.js",
5+
"./main.chunk.js"
6+
]
7+
}
8+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const SingleEntryPlugin = require("../../../../lib/SingleEntryPlugin");
2+
module.exports = {
3+
entry: () => ({}),
4+
optimization: {
5+
runtimeChunk: true
6+
},
7+
output: {
8+
filename: "[name].js",
9+
chunkFilename: "[name].chunk.js"
10+
},
11+
target: "web",
12+
plugins: [
13+
new SingleEntryPlugin(__dirname, "./fail", "main"),
14+
new SingleEntryPlugin(__dirname, "./ok", "main")
15+
]
16+
};

0 commit comments

Comments
 (0)