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:
Tobias Koppers 2018-08-03 11:09:26 +02:00
parent 5539f57ba8
commit 17ebfb9784
5 changed files with 42 additions and 2 deletions

View File

@ -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);
}

View File

@ -0,0 +1,3 @@
it("should load correct entry", function() {
throw new Error("This entrypoint should not be used");
});

View File

@ -0,0 +1,3 @@
it("should load correct entry", function() {
// ok
});

View File

@ -0,0 +1,8 @@
module.exports = {
findBundle: function() {
return [
"./runtime~main.js",
"./main.chunk.js"
]
}
};

View File

@ -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")
]
};