Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add chunkLoading: false support #14692

Merged
merged 1 commit into from Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 25 additions & 5 deletions lib/buildChunkGraph.js
Expand Up @@ -50,6 +50,7 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
* @property {Set<ChunkGroupInfo>} availableChildren set of chunk groups which depend on the this chunk group as availableSource
* @property {number} preOrderIndex next pre order index
* @property {number} postOrderIndex next post order index
* @property {boolean} asyncChunkLoading create async chunks
*/

/**
Expand Down Expand Up @@ -304,7 +305,11 @@ const visitModules = (
availableSources: undefined,
availableChildren: undefined,
preOrderIndex: 0,
postOrderIndex: 0
postOrderIndex: 0,
asyncChunkLoading:
chunkGroup.options.chunkLoading === false
? false
: compilation.outputOptions.chunkLoading !== false
};
chunkGroup.index = nextChunkGroupIndex++;
if (chunkGroup.getNumberOfParents() > 0) {
Expand Down Expand Up @@ -418,7 +423,11 @@ const visitModules = (
availableSources: undefined,
availableChildren: undefined,
preOrderIndex: 0,
postOrderIndex: 0
postOrderIndex: 0,
asyncChunkLoading:
entryOptions.chunkLoading !== undefined
? entryOptions.chunkLoading !== false
: chunkGroupInfo.asyncChunkLoading
};
chunkGroupInfoMap.set(entrypoint, cgi);

Expand All @@ -442,8 +451,18 @@ const visitModules = (
chunkGroup: entrypoint,
chunkGroupInfo: cgi
});
} else if (!chunkGroupInfo.asyncChunkLoading) {
// Just queue the block into the current chunk group
queue.push({
action: PROCESS_BLOCK,
block: b,
module: module,
chunk,
chunkGroup,
chunkGroupInfo
});
} else {
cgi = namedChunkGroups.get(chunkName);
cgi = chunkName && namedChunkGroups.get(chunkName);
if (!cgi) {
c = compilation.addChunkInGroup(
b.groupOptions || b.chunkName,
Expand All @@ -464,7 +483,8 @@ const visitModules = (
availableSources: undefined,
availableChildren: undefined,
preOrderIndex: 0,
postOrderIndex: 0
postOrderIndex: 0,
asyncChunkLoading: chunkGroupInfo.asyncChunkLoading
};
allCreatedChunkGroups.add(c);
chunkGroupInfoMap.set(c, cgi);
Expand Down Expand Up @@ -518,7 +538,7 @@ const visitModules = (
chunkGroup: c,
chunkGroupInfo: cgi
});
} else {
} else if (entrypoint !== undefined) {
chunkGroupInfo.chunkGroup.addAsyncEntrypoint(entrypoint);
}
};
Expand Down
12 changes: 12 additions & 0 deletions test/configCases/entry/no-chunking/a.js
@@ -0,0 +1,12 @@
import fs from "fs";

it("should load chunks on demand", async () => {
expect((await import("./async")).default).toEqual(42);
expect((await (await import("./async")).nested()).default).toEqual(43);
expect(fs.readFileSync(__filename, "utf-8")).not.toContain(
"This is the" + " async chunk"
);
expect(fs.readFileSync(__filename, "utf-8")).not.toContain(
"This is the" + " nested async chunk"
);
});
3 changes: 3 additions & 0 deletions test/configCases/entry/no-chunking/async.js
@@ -0,0 +1,3 @@
// This is the async chunk
export default 42;
export const nested = () => import("./nested");
12 changes: 12 additions & 0 deletions test/configCases/entry/no-chunking/b.js
@@ -0,0 +1,12 @@
import fs from "fs";

it("should include all async imports in the main chunk", async () => {
expect((await import("./async")).default).toEqual(42);
expect((await (await import("./async")).nested()).default).toEqual(43);
expect(fs.readFileSync(__filename, "utf-8")).toContain(
"This is the async chunk"
);
expect(fs.readFileSync(__filename, "utf-8")).toContain(
"This is the nested async chunk"
);
});
2 changes: 2 additions & 0 deletions test/configCases/entry/no-chunking/nested.js
@@ -0,0 +1,2 @@
// This is the nested async chunk
export default 43;
5 changes: 5 additions & 0 deletions test/configCases/entry/no-chunking/test.config.js
@@ -0,0 +1,5 @@
module.exports = {
findBundle: function (i, options) {
return ["./a.js", "./b.js"];
}
};
13 changes: 13 additions & 0 deletions test/configCases/entry/no-chunking/webpack.config.js
@@ -0,0 +1,13 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
entry: {
a: "./a.js",
b: {
import: "./b.js",
chunkLoading: false
}
},
output: {
filename: "[name].js"
}
};