fix #7829
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
This commit is contained in:
parent
5539f57ba8
commit
17ebfb9784
|
@ -1025,6 +1025,7 @@ class Compilation extends Tapable {
|
|||
addEntry(context, entry, name, callback) {
|
||||
const slot = {
|
||||
name: name,
|
||||
// TODO webpack 5 remove `request`
|
||||
request: null,
|
||||
module: null
|
||||
};
|
||||
|
@ -1033,7 +1034,14 @@ class Compilation extends Tapable {
|
|||
slot.request = entry.request;
|
||||
}
|
||||
|
||||
this._preparedEntrypoints.push(slot);
|
||||
// TODO webpack 5: merge modules instead when multiple entry modules are supported
|
||||
const idx = this._preparedEntrypoints.findIndex(slot => slot.name === name);
|
||||
if (idx >= 0) {
|
||||
// Overwrite existing entrypoint
|
||||
this._preparedEntrypoints[idx] = slot;
|
||||
} else {
|
||||
this._preparedEntrypoints.push(slot);
|
||||
}
|
||||
this._addModuleChain(
|
||||
context,
|
||||
entry,
|
||||
|
@ -1049,7 +1057,9 @@ class Compilation extends Tapable {
|
|||
slot.module = module;
|
||||
} else {
|
||||
const idx = this._preparedEntrypoints.indexOf(slot);
|
||||
this._preparedEntrypoints.splice(idx, 1);
|
||||
if (idx >= 0) {
|
||||
this._preparedEntrypoints.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
return callback(null, module);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
it("should load correct entry", function() {
|
||||
throw new Error("This entrypoint should not be used");
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
it("should load correct entry", function() {
|
||||
// ok
|
||||
});
|
|
@ -0,0 +1,8 @@
|
|||
module.exports = {
|
||||
findBundle: function() {
|
||||
return [
|
||||
"./runtime~main.js",
|
||||
"./main.chunk.js"
|
||||
]
|
||||
}
|
||||
};
|
|
@ -0,0 +1,16 @@
|
|||
const SingleEntryPlugin = require("../../../../lib/SingleEntryPlugin");
|
||||
module.exports = {
|
||||
entry: () => ({}),
|
||||
optimization: {
|
||||
runtimeChunk: true
|
||||
},
|
||||
output: {
|
||||
filename: "[name].js",
|
||||
chunkFilename: "[name].chunk.js"
|
||||
},
|
||||
target: "web",
|
||||
plugins: [
|
||||
new SingleEntryPlugin(__dirname, "./fail", "main"),
|
||||
new SingleEntryPlugin(__dirname, "./ok", "main")
|
||||
]
|
||||
};
|
Loading…
Reference in New Issue