Skip to content

Commit

Permalink
Merge pull request #7842 from webpack/bugfix/override-entry
Browse files Browse the repository at this point in the history
fix #7829
  • Loading branch information
sokra committed Aug 3, 2018
2 parents 5539f57 + 17ebfb9 commit 4972fd8
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 4972fd8

Please sign in to comment.