Skip to content

Commit c26c872

Browse files
committed
add "single" option to RuntimeChunkPlugin
1 parent c963e3d commit c26c872

11 files changed

Lines changed: 65 additions & 4 deletions

File tree

lib/WebpackOptionsApply.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class WebpackOptionsApply extends OptionsApply {
291291
if(options.optimization.splitChunks)
292292
new SplitChunksPlugin(options.optimization.splitChunks).apply(compiler);
293293
if(options.optimization.runtimeChunk)
294-
new RuntimeChunkPlugin().apply(compiler);
294+
new RuntimeChunkPlugin(options.optimization.runtimeChunk).apply(compiler);
295295
if(options.optimization.noEmitOnErrors)
296296
new NoEmitOnErrorsPlugin().apply(compiler);
297297
if(options.optimization.namedModules)

lib/optimize/RuntimeChunkPlugin.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
"use strict";
66

77
module.exports = class RuntimeChunkPlugin {
8-
constructor(options) {}
8+
constructor(options) {
9+
this.single = options === "single";
10+
}
911

1012
apply(compiler) {
1113
compiler.hooks.thisCompilation.tap("RuntimeChunkPlugin", compilation => {
1214
compilation.hooks.optimizeChunksAdvanced.tap("RuntimeChunkPlugin", () => {
15+
const singleRuntimeChunk = this.single ? compilation.addChunk("runtime") : undefined;
16+
1317
for(const entrypoint of compilation.entrypoints.values()) {
1418
const chunk = entrypoint.getRuntimeChunk();
1519
if(chunk.getNumberOfModules() > 0) {
16-
const newChunk = compilation.addChunk(entrypoint.name + "-runtime");
20+
const newChunk = this.single ? singleRuntimeChunk : compilation.addChunk(entrypoint.name + "-runtime");
1721
entrypoint.unshiftChunk(newChunk);
1822
newChunk.addGroup(entrypoint);
1923
entrypoint.setRuntimeChunk(newChunk);

schemas/WebpackOptions.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,16 @@
14841484
},
14851485
"runtimeChunk": {
14861486
"description": "Create an additional chunk which contains only the webpack runtime and chunk hash maps",
1487-
"type": "boolean"
1487+
"oneOf": [
1488+
{
1489+
"type": "boolean"
1490+
},
1491+
{
1492+
"enum": [
1493+
"single"
1494+
]
1495+
}
1496+
]
14881497
},
14891498
"noEmitOnErrors": {
14901499
"description": "Avoid emitting assets when errors occur",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "entry1";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "entry2";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Entrypoint e1 = runtime.js e1.js
2+
Entrypoint e2 = runtime.js e2.js
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
mode: "development",
3+
entry: {
4+
e1: "./e1",
5+
e2: "./e2"
6+
},
7+
output: {
8+
filename: "[name].js"
9+
},
10+
stats: {
11+
hash: false,
12+
timings: false,
13+
assets: false,
14+
modules: false,
15+
reasons: true
16+
},
17+
optimization: {
18+
runtimeChunk: "single"
19+
}
20+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "entry1";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "entry2";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Entrypoint e1 = e1-runtime.js e1.js
2+
Entrypoint e2 = e2-runtime.js e2.js

0 commit comments

Comments
 (0)