Skip to content

Commit 52a61ed

Browse files
EugeneHlushkomontogeek
authored andcommitted
docs(plugins) Update SCP test info (#2577)
1 parent 9c040c1 commit 52a61ed

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

src/content/plugins/split-chunks-plugin.md

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ By default it only affects on-demand chunks, because changing initial chunks wou
3030

3131
webpack will automatically split chunks based on these conditions:
3232

33-
* New chunk can be shared OR modules are from the `node_modules` folder
34-
* New chunk would be bigger than 30kb (before min+gz)
35-
* Maximum number of parallel requests when loading chunks on demand would be lower or equal to 5
36-
* Maximum number of parallel requests at initial page load would be lower or equal to 3
33+
- New chunk can be shared OR modules are from the `node_modules` folder
34+
- New chunk would be bigger than 30kb (before min+gz)
35+
- Maximum number of parallel requests when loading chunks on demand would be lower or equal to 5
36+
- Maximum number of parallel requests at initial page load would be lower or equal to 3
3737

3838
When trying to fulfill the last two conditions, bigger chunks are preferred.
3939

@@ -47,6 +47,8 @@ W> The default configuration was chosen to fit web performance best practices, b
4747

4848
This configuration object represents the default behavior of the `SplitChunksPlugin`.
4949

50+
__webpack.config.js__
51+
5052
```js
5153
module.exports = {
5254
//...
@@ -85,10 +87,12 @@ By default webpack will generate names using origin and name of the chunk (e.g.
8587

8688
### `splitChunks.chunks`
8789

88-
`function` `string`
90+
`function | string`
8991

9092
This indicates which chunks will be selected for optimization. When a string is provided, valid values are `all`, `async`, and `initial`. Providing `all` can be particularly powerful, because it means that chunks can be shared even between async and non-async chunks.
9193

94+
__webpack.config.js__
95+
9296
```js
9397
module.exports = {
9498
//...
@@ -158,10 +162,12 @@ T> `maxSize` takes higher priority than `maxInitialRequest/maxAsyncRequests`. Ac
158162

159163
### `splitChunks.name`
160164

161-
`boolean: true` `function` `string`
165+
`boolean: true | function | string`
162166

163167
The name of the split chunk. Providing `true` will automatically generate a name based on chunks and cache group key. Providing a string or function will allow you to use a custom name. If the name matches an entry point name, the entry point will be removed.
164168

169+
__webpack.config.js__
170+
165171
```js
166172
module.exports = {
167173
//...
@@ -182,6 +188,8 @@ W> When assigning equal names to different split chunks, all vendor modules are
182188

183189
Cache groups can inherit and/or override any options from `splitChunks.*`; but `test`, `priority` and `reuseExistingChunk` can only be configured on cache group level. To disable any of the default cache groups, set them to `false`.
184190

191+
__webpack.config.js__
192+
185193
```js
186194
module.exports = {
187195
//...
@@ -207,6 +215,8 @@ A module can belong to multiple cache groups. The optimization will prefer the c
207215

208216
If the current chunk contains modules already split out from the main bundle, it will be reused instead of a new one being generated. This can impact the resulting file name of the chunk.
209217

218+
__webpack.config.js__
219+
210220
```js
211221
module.exports = {
212222
//...
@@ -222,22 +232,24 @@ module.exports = {
222232
};
223233
```
224234

225-
#### `splitChunks.cacheGroups.test`
235+
#### `splitChunks.cacheGroups.{cacheGroup}.test`
226236

227-
`function` `RegExp` `string`
237+
`function | RegExp | string`
228238

229239
Controls which modules are selected by this cache group. Omitting it selects all modules. It can match the absolute module resource path or chunk names. When a chunk name is matched, all modules in the chunk are selected.
230240

241+
__webpack.config.js__
242+
231243
```js
232244
module.exports = {
233245
//...
234246
optimization: {
235247
splitChunks: {
236248
cacheGroups: {
237249
vendors: {
238-
test (chunks) {
250+
test (module, chunks) {
239251
//...
240-
return true;
252+
return module.type === 'javascript/auto';
241253
}
242254
}
243255
}
@@ -263,14 +275,14 @@ import 'react';
263275
//...
264276
```
265277

266-
**Result:** A separate chunk would be created containing `react`. At the import call this chunk is loaded in parallel to the original chunk containing `./a`.
278+
__Result:__ A separate chunk would be created containing `react`. At the import call this chunk is loaded in parallel to the original chunk containing `./a`.
267279

268280
Why:
269281

270-
* Condition 1: The chunk contains modules from `node_modules`
271-
* Condition 2: `react` is bigger than 30kb
272-
* Condition 3: Number of parallel requests at the import call is 2
273-
* Condition 4: Doesn't affect request at initial page load
282+
- Condition 1: The chunk contains modules from `node_modules`
283+
- Condition 2: `react` is bigger than 30kb
284+
- Condition 3: Number of parallel requests at the import call is 2
285+
- Condition 4: Doesn't affect request at initial page load
274286

275287
What's the reasoning behind this? `react` probably won't change as often as your application code. By moving it into a separate chunk this chunk can be cached separately from your app code (assuming you are using chunkhash, records, Cache-Control or other long term cache approach).
276288

@@ -299,14 +311,14 @@ import './more-helpers'; // more-helpers is also 40kb in size
299311
//...
300312
```
301313

302-
**Result:** A separate chunk would be created containing `./helpers` and all dependencies of it. At the import calls this chunk is loaded in parallel to the original chunks.
314+
__Result:__ A separate chunk would be created containing `./helpers` and all dependencies of it. At the import calls this chunk is loaded in parallel to the original chunks.
303315

304316
Why:
305317

306-
* Condition 1: The chunk is shared between both import calls
307-
* Condition 2: `helpers` is bigger than 30kb
308-
* Condition 3: Number of parallel requests at the import calls is 2
309-
* Condition 4: Doesn't affect request at initial page load
318+
- Condition 1: The chunk is shared between both import calls
319+
- Condition 2: `helpers` is bigger than 30kb
320+
- Condition 3: Number of parallel requests at the import calls is 2
321+
- Condition 4: Doesn't affect request at initial page load
310322

311323
Putting the content of `helpers` into each chunk will result into its code being downloaded twice. By using a separate chunk this will only happen once. We pay the cost of an additional request, which could be considered a tradeoff. That's why there is a minimum size of 30kb.
312324

@@ -316,7 +328,6 @@ Create a `commons` chunk, which includes all code shared between entry points.
316328

317329
__webpack.config.js__
318330

319-
320331
```js
321332
module.exports = {
322333
//...
@@ -342,7 +353,6 @@ Create a `vendors` chunk, which includes all code from `node_modules` in the who
342353

343354
__webpack.config.js__
344355

345-
346356
```js
347357
module.exports = {
348358
//...

0 commit comments

Comments
 (0)