Skip to content

Commit

Permalink
Merge pull request #7062 from webpack/bugfix/issue-6931
Browse files Browse the repository at this point in the history
fix bug which prevented some chunks to show up in Chunk.getAllAsyncChunks
  • Loading branch information
sokra committed Apr 17, 2018
2 parents 3f99517 + 58ba91d commit 3a5fda9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/Chunk.js
Expand Up @@ -6,6 +6,7 @@

const util = require("util");
const SortableSet = require("./util/SortableSet");
const intersect = require("./util/SetHelpers").intersect;
const GraphHelpers = require("./GraphHelpers");
let debugId = 1000;
const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
Expand Down Expand Up @@ -321,12 +322,15 @@ class Chunk {
}

getAllAsyncChunks() {
const initialChunks = new Set();
const queue = new Set(this.groupsIterable);
const queue = new Set();
const chunks = new Set();

for (const chunkGroup of queue) {
for (const chunk of chunkGroup.chunks) initialChunks.add(chunk);
const initialChunks = intersect(
Array.from(this.groupsIterable, g => new Set(g.chunks))
);

for (const chunkGroup of this.groupsIterable) {
for (const child of chunkGroup.childrenIterable) queue.add(child);
}

for (const chunkGroup of queue) {
Expand Down
17 changes: 17 additions & 0 deletions test/configCases/split-chunks/runtime-chunk/a.js
@@ -0,0 +1,17 @@
const should = require("should");
const FakeDocument = require("../../../helpers/FakeDocument");

beforeEach(() => {
global.document = new FakeDocument();
});

afterEach(() => {
delete global.document;
})

it("should be able to load the split chunk on demand", () => {
const promise = import(/* webpackChunkName: "shared" */ "./shared");

const script = document.head._children[0];
should(script.src).be.eql("dep~b~shared.js");
});
1 change: 1 addition & 0 deletions test/configCases/split-chunks/runtime-chunk/b.js
@@ -0,0 +1 @@
import "./shared";
Empty file.
5 changes: 5 additions & 0 deletions test/configCases/split-chunks/runtime-chunk/test.config.js
@@ -0,0 +1,5 @@
module.exports = {
findBundle: function(i, options) {
return ["runtime.js", "a.js"];
}
};
24 changes: 24 additions & 0 deletions test/configCases/split-chunks/runtime-chunk/webpack.config.js
@@ -0,0 +1,24 @@
const path = require("path");

module.exports = {
entry: {
a: "./a",
b: "./b"
},
target: "web",
output: {
filename: "[name].js"
},
optimization: {
runtimeChunk: "single",
splitChunks: {
cacheGroups: {
dep: {
chunks: "all",
test: path.resolve(__dirname, "shared.js"),
enforce: true
}
}
}
}
};

0 comments on commit 3a5fda9

Please sign in to comment.