|
| 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