Skip to content

Commit 1677144

Browse files
committed
Allow filter function in optimization.splitChunks.cacheGroups[name].chunks
1 parent 1e2d8ec commit 1677144

File tree

3 files changed

+100
-5
lines changed

3 files changed

+100
-5
lines changed

schemas/WebpackOptions.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,10 +1434,17 @@
14341434
},
14351435
"chunks": {
14361436
"description": "Select chunks for determining cache group content (defaults to \"initial\", \"initial\" and \"all\" requires adding these chunks to the HTML)",
1437-
"enum": [
1438-
"initial",
1439-
"async",
1440-
"all"
1437+
"oneOf": [
1438+
{
1439+
"enum": [
1440+
"initial",
1441+
"async",
1442+
"all"
1443+
]
1444+
},
1445+
{
1446+
"instanceof": "Function"
1447+
}
14411448
]
14421449
},
14431450
"enforce": {

test/statsCases/split-chunks/expected.txt

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,61 @@ Child custom-chunks-filter:
325325
> ./c c
326326
[0] ./d.js 20 bytes {1} {10} {11} {12} [built]
327327
[1] ./f.js 20 bytes {2} {11} {12} [built]
328-
[5] ./c.js 72 bytes {8} {12} [built]
328+
[5] ./c.js 72 bytes {8} {12} [built]
329+
Child custom-chunks-filter-in-cache-groups:
330+
Entrypoint main = default/main.js
331+
Entrypoint a = default/a.js
332+
Entrypoint b = default/vendors.js default/b.js
333+
Entrypoint c = default/vendors.js default/c.js
334+
chunk {0} default/vendors.js (vendors) 112 bytes <{5}> ={2}= ={3}= ={4}= ={7}= ={8}= >{1}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors)
335+
> ./b b
336+
> ./c c
337+
> ./a [8] ./index.js 1:0-47
338+
> ./b [8] ./index.js 2:0-47
339+
> ./c [8] ./index.js 3:0-47
340+
[2] ./node_modules/x.js 20 bytes {0} {6} [built]
341+
[3] ./node_modules/y.js 20 bytes {0} {6} [built]
342+
[6] ./node_modules/z.js 20 bytes {0} [built]
343+
[10] multi x y z 52 bytes {0} [built]
344+
chunk {1} default/async-g.js (async-g) 54 bytes <{0}> <{2}> <{6}> [rendered]
345+
> ./g [] 6:0-47
346+
> ./g [] 6:0-47
347+
[1] ./f.js 20 bytes {1} {3} {4} {7} {8} [built]
348+
[9] ./g.js 34 bytes {1} [built]
349+
chunk {2} default/async-a.js (async-a) 176 bytes <{5}> ={0}= >{1}< [rendered]
350+
> ./a [8] ./index.js 1:0-47
351+
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
352+
[7] ./a.js + 1 modules 156 bytes {2} {6} [built]
353+
| ./a.js 121 bytes [built]
354+
| ./e.js 20 bytes [built]
355+
chunk {3} default/async-b.js (async-b) 112 bytes <{5}> ={0}= [rendered]
356+
> ./b [8] ./index.js 2:0-47
357+
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
358+
[1] ./f.js 20 bytes {1} {3} {4} {7} {8} [built]
359+
[4] ./b.js 72 bytes {3} {7} [built]
360+
chunk {4} default/async-c.js (async-c) 112 bytes <{5}> ={0}= [rendered]
361+
> ./c [8] ./index.js 3:0-47
362+
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
363+
[1] ./f.js 20 bytes {1} {3} {4} {7} {8} [built]
364+
[5] ./c.js 72 bytes {4} {8} [built]
365+
chunk {5} default/main.js (main) 147 bytes >{0}< >{2}< >{3}< >{4}< [entry] [rendered]
366+
> ./ main
367+
[8] ./index.js 147 bytes {5} [built]
368+
chunk {6} default/a.js (a) 216 bytes >{1}< [entry] [rendered]
369+
> ./a a
370+
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
371+
[2] ./node_modules/x.js 20 bytes {0} {6} [built]
372+
[3] ./node_modules/y.js 20 bytes {0} {6} [built]
373+
[7] ./a.js + 1 modules 156 bytes {2} {6} [built]
374+
| ./a.js 121 bytes [built]
375+
| ./e.js 20 bytes [built]
376+
chunk {7} default/b.js (b) 112 bytes ={0}= [entry] [rendered]
377+
> ./b b
378+
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
379+
[1] ./f.js 20 bytes {1} {3} {4} {7} {8} [built]
380+
[4] ./b.js 72 bytes {3} {7} [built]
381+
chunk {8} default/c.js (c) 112 bytes ={0}= [entry] [rendered]
382+
> ./c c
383+
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
384+
[1] ./f.js 20 bytes {1} {3} {4} {7} {8} [built]
385+
[5] ./c.js 72 bytes {4} {8} [built]

test/statsCases/split-chunks/webpack.config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,36 @@ module.exports = [
119119
}
120120
},
121121
stats
122+
},
123+
124+
{
125+
name: "custom-chunks-filter-in-cache-groups",
126+
mode: "production",
127+
entry: {
128+
main: "./",
129+
a: "./a",
130+
b: "./b",
131+
c: "./c",
132+
vendors: ["x", "y", "z"]
133+
},
134+
output: {
135+
filename: "default/[name].js"
136+
},
137+
optimization: {
138+
splitChunks: {
139+
minSize: 0,
140+
chunks: "all",
141+
cacheGroups: {
142+
default: false,
143+
vendors: {
144+
test: "vendors",
145+
name: "vendors",
146+
enforce: true,
147+
chunks: chunk => chunk.name !== "a"
148+
}
149+
}
150+
}
151+
},
152+
stats
122153
}
123154
];

0 commit comments

Comments
 (0)