Skip to content

Commit

Permalink
fix #7829
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sokra committed Aug 3, 2018
1 parent 5539f57 commit 17ebfb9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/Compilation.js
Expand Up @@ -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
};
Expand All @@ -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,
Expand All @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions test/configCases/entry/override-entry-point/fail.js
@@ -0,0 +1,3 @@
it("should load correct entry", function() {
throw new Error("This entrypoint should not be used");
});
3 changes: 3 additions & 0 deletions test/configCases/entry/override-entry-point/ok.js
@@ -0,0 +1,3 @@
it("should load correct entry", function() {
// ok
});
8 changes: 8 additions & 0 deletions test/configCases/entry/override-entry-point/test.config.js
@@ -0,0 +1,8 @@
module.exports = {
findBundle: function() {
return [
"./runtime~main.js",
"./main.chunk.js"
]
}
};
16 changes: 16 additions & 0 deletions test/configCases/entry/override-entry-point/webpack.config.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")
]
};

0 comments on commit 17ebfb9

Please sign in to comment.