Skip to content

Commit 3a5fda9

Browse files
authored
Merge pull request webpack#7062 from webpack/bugfix/issue-6931
fix bug which prevented some chunks to show up in Chunk.getAllAsyncChunks
2 parents 3f99517 + 58ba91d commit 3a5fda9

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed

lib/Chunk.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const util = require("util");
88
const SortableSet = require("./util/SortableSet");
9+
const intersect = require("./util/SetHelpers").intersect;
910
const GraphHelpers = require("./GraphHelpers");
1011
let debugId = 1000;
1112
const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
@@ -321,12 +322,15 @@ class Chunk {
321322
}
322323

323324
getAllAsyncChunks() {
324-
const initialChunks = new Set();
325-
const queue = new Set(this.groupsIterable);
325+
const queue = new Set();
326326
const chunks = new Set();
327327

328-
for (const chunkGroup of queue) {
329-
for (const chunk of chunkGroup.chunks) initialChunks.add(chunk);
328+
const initialChunks = intersect(
329+
Array.from(this.groupsIterable, g => new Set(g.chunks))
330+
);
331+
332+
for (const chunkGroup of this.groupsIterable) {
333+
for (const child of chunkGroup.childrenIterable) queue.add(child);
330334
}
331335

332336
for (const chunkGroup of queue) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const should = require("should");
2+
const FakeDocument = require("../../../helpers/FakeDocument");
3+
4+
beforeEach(() => {
5+
global.document = new FakeDocument();
6+
});
7+
8+
afterEach(() => {
9+
delete global.document;
10+
})
11+
12+
it("should be able to load the split chunk on demand", () => {
13+
const promise = import(/* webpackChunkName: "shared" */ "./shared");
14+
15+
const script = document.head._children[0];
16+
should(script.src).be.eql("dep~b~shared.js");
17+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./shared";

test/configCases/split-chunks/runtime-chunk/shared.js

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
findBundle: function(i, options) {
3+
return ["runtime.js", "a.js"];
4+
}
5+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const path = require("path");
2+
3+
module.exports = {
4+
entry: {
5+
a: "./a",
6+
b: "./b"
7+
},
8+
target: "web",
9+
output: {
10+
filename: "[name].js"
11+
},
12+
optimization: {
13+
runtimeChunk: "single",
14+
splitChunks: {
15+
cacheGroups: {
16+
dep: {
17+
chunks: "all",
18+
test: path.resolve(__dirname, "shared.js"),
19+
enforce: true
20+
}
21+
}
22+
}
23+
}
24+
};

0 commit comments

Comments
 (0)