Skip to content

Commit

Permalink
Merge pull request #13334 from webpack/bugfix/depend-on-runtime-async…
Browse files Browse the repository at this point in the history
…-chunks
  • Loading branch information
sokra committed May 10, 2021
2 parents 81854de + f98c65a commit 84ae69b
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/Chunk.js
Expand Up @@ -568,9 +568,15 @@ class Chunk {
Array.from(this.groupsIterable, g => new Set(g.chunks))
);

for (const chunkGroup of this.groupsIterable) {
const initialQueue = new Set(this.groupsIterable);

for (const chunkGroup of initialQueue) {
for (const child of chunkGroup.childrenIterable) {
queue.add(child);
if (child instanceof Entrypoint) {
initialQueue.add(child);
} else {
queue.add(child);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions test/configCases/runtime/entries-in-runtime/async.js
@@ -0,0 +1 @@
console.log("split");
11 changes: 11 additions & 0 deletions test/configCases/runtime/entries-in-runtime/index.js
@@ -0,0 +1,11 @@
import path from "path";
import fs from "fs";

it("should not have references to chunks of unrelated entrypoints in runtime", () => {
const content = fs.readFileSync(
path.resolve(__dirname, "runtime.js"),
"utf-8"
);
expect(content).not.toContain("other-entry");
expect(content).not.toContain("split");
});
Empty file.
2 changes: 2 additions & 0 deletions test/configCases/runtime/entries-in-runtime/other-entry.js
@@ -0,0 +1,2 @@
import "./split";
import("./async");
1 change: 1 addition & 0 deletions test/configCases/runtime/entries-in-runtime/split.js
@@ -0,0 +1 @@
console.log("split");
5 changes: 5 additions & 0 deletions test/configCases/runtime/entries-in-runtime/test.config.js
@@ -0,0 +1,5 @@
module.exports = {
findBundle: function () {
return ["./runtime.js", "./main.js", "./first-entry.js"];
}
};
39 changes: 39 additions & 0 deletions test/configCases/runtime/entries-in-runtime/webpack.config.js
@@ -0,0 +1,39 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "production",
entry: {
main: "./main",
"first-entry": {
dependOn: "main",
import: "./index"
},
"other-entry": {
dependOn: "main",
import: "./other-entry"
}
},
target: "web",
node: {
__dirname: false,
__filename: false
},
externalsPresets: {
node: true
},
output: {
filename: "[name].js"
},
optimization: {
runtimeChunk: "single",
splitChunks: {
cacheGroups: {
split: {
chunks: "all",
name: "split",
test: /split\.js$/,
enforce: true
}
}
}
}
};

0 comments on commit 84ae69b

Please sign in to comment.