Skip to content

Commit 369d381

Browse files
authored
docs(performance): Add performance config documentation (#500)
* docs(performance): Add performance config documentation
1 parent b8ff99c commit 369d381

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

content/configuration/index.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,19 @@ T> Notice that throughout the configuration we use Node's built-in [path module]
285285
</details>
286286
},
287287
288+
[performance](/configuration/performance): {
289+
<details><summary>[hints](/configuration/performance#performance-hints): "warning", // enum </summary>
290+
[hints](/configuration/performance#performance-hints): "error", // emit errors for perf hints
291+
[hints](/configuration/performance#performance-hints): false, // turn off perf hints
292+
</details>
293+
[maxAssetSize](/configuration/performance#performance-maxassetsize): 200000, // int (in bytes),
294+
[maxEntrypointSize](/configuration/performance#performance-maxentrypointsize): 400000, // int (in bytes)
295+
[assetFilter](/configuration/performance#performance-assetfilter): function(assetFilename) {
296+
// Function predicate that provides asset filenames
297+
return assetName.endsWith('.css') || assetName.endsWith('.js');
298+
}
299+
},
300+
288301
<details><summary>[devtool](/configuration/devtool): "source-map", // enum </summary>
289302
[devtool](/configuration/devtool): "inline-source-map", // inlines SourceMap into orginal file
290303
[devtool](/configuration/devtool): "eval-source-map", // inlines SourceMap per module
@@ -341,7 +354,8 @@ T> Notice that throughout the configuration we use Node's built-in [path module]
341354
// ...
342355
],
343356
// list of additional plugins
344-
357+
358+
345359
<details><summary>/* Advanced configuration (click to show) */</summary>
346360
347361
[resolveLoader](/configuration/resolve#resolveloader): { /* same as resolve */ }

content/configuration/performance.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: Performance
3+
sort: 14
4+
contributors:
5+
- thelarkinn
6+
---
7+
8+
These options allows you to control how webpack notifies you of assets and entrypoints that exceed a specific file limit.
9+
This feature was inspired by the idea of [webpack Performance Budgets](https://github.com/webpack/webpack/issues/3216).
10+
11+
## `performance`
12+
13+
`object`
14+
15+
Configure how performance hints are shown. For example if you have an asset that is over 250kb, webpack will emit a warning notifiying you of this.
16+
17+
18+
## `performance.hints`
19+
20+
`boolean | "error" | "warning"`
21+
22+
Turns hints on/off. In addition, tells webpack to throw either an error or a warning when hints are found. This property is set to `"warning"` by default.
23+
24+
Given an asset is created that is over 250kb:
25+
26+
```js
27+
performance: {
28+
hints: false
29+
}
30+
```
31+
32+
No hint warnings or errors are shown.
33+
34+
```js
35+
performance: {
36+
hints: "warning"
37+
}
38+
```
39+
40+
A warning will be displayed notifying you of a large asset. We recommend something like this for development environments.
41+
42+
```js
43+
performance: {
44+
hints: "error"
45+
}
46+
```
47+
48+
An error will be displayed notifying you of a large asset. We recommend using `hints: "error"` during production builds to help prevent deploying production bundles that are too large, impacting webpage performance.
49+
50+
## `performance.maxEntrypointSize`
51+
52+
`int`
53+
54+
An entrypoint represents all assets that would be utilized during initial load time for a specific entry. This option controls when webpack should emit performance hints based on the maximum entrypoint size. The default value is `250000` (bytes).
55+
56+
```js
57+
performance: {
58+
maxEntrypointSize: 400000
59+
}
60+
```
61+
62+
## `performance.maxAssetSize`
63+
64+
`int`
65+
66+
An asset is any emitted file from webpack. This option controls when webpack emits a performance hint based on individual asset size. The default value is `250000` (bytes).
67+
68+
69+
```js
70+
performance: {
71+
maxAssetSize: 100000
72+
}
73+
```
74+
75+
## `performance.assetFilter`
76+
77+
`Function`
78+
79+
This property allows webpack to control what files are used to calculate performance hints. The default function is seen below:
80+
81+
```js
82+
function(assetFilename) {
83+
return !(/\.map$/.test(assetFilename))
84+
};
85+
```
86+
87+
You can override this property by passing your own function in:
88+
89+
```js
90+
performance: {
91+
assetFilter: function(assetFilename) {
92+
return assetFilename.endsWith('.js');
93+
}
94+
}
95+
```
96+
97+
The example above will only give you performance hints based on `.js` files.

0 commit comments

Comments
 (0)