Skip to content

Commit 774a89b

Browse files
TheLarkInnsokra
authored andcommitted
feat(perfbudgets): added errorOnHint flag defaulting to false for opt-in
1 parent 000dae1 commit 774a89b

12 files changed

Lines changed: 63 additions & 3 deletions

File tree

‎lib/WebpackOptionsDefaulter.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function WebpackOptionsDefaulter() {
1616
this.set("performance.maxInitialChunkSize", 300);
1717
this.set("performance.maxAssetSize", 300000);
1818
this.set("performance.hints", true);
19+
this.set("performance.errorOnHint", false);
1920

2021
this.set("module.unknownContextRequest", ".");
2122
this.set("module.unknownContextRegExp", false);

‎lib/performance/EmittedAssetSizeLimitPlugin.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function EmittedAssetSizeLimitPlugin(performanceOptions) {
1111
this.maxAssetSize = performanceOptions.maxAssetSize;
1212
this.maxInitialSize = performanceOptions.maxInitialChunkSize;
1313
this.hints = performanceOptions.hints;
14+
this.errorOnHint = performanceOptions.errorOnHint;
1415
}
1516

1617
module.exports = EmittedAssetSizeLimitPlugin;
@@ -44,10 +45,10 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
4445
if(!this.hints) {
4546
return;
4647
}
47-
4848
var entrypointSizeLimit = this.maxInitialSize;
4949
var sizeLimit = this.maxAssetSize;
5050
var hints = this.hints;
51+
var shouldErrorOnHint = this.errorOnHint;
5152

5253
compiler.plugin("after-emit", function(compilation, callback) {
5354
var warnings = [];
@@ -140,7 +141,6 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
140141
// 3. No Async Chunks
141142
// if !1, then 2, if !2 return
142143
// if 1, then 2, then 3,
143-
144144
if(assetsOverSizeLimit.length) {
145145
warnings.push(new AssetsOverSizeLimitWarning(assetsOverSizeLimit, compilation, formatSize, sizeLimit));
146146
warnings.push(new EntrypointsOverSizeLimitWarning(entrypointsOverSizeLimit, compilation, formatSize, entrypointSizeLimit));
@@ -165,7 +165,11 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
165165
}
166166

167167
if(warnings.length) {
168-
Array.prototype.push.apply(compilation.warnings, warnings);
168+
if(shouldErrorOnHint) {
169+
Array.prototype.push.apply(compilation.errors, warnings);
170+
} else {
171+
Array.prototype.push.apply(compilation.warnings, warnings);
172+
}
169173
}
170174

171175
callback();

‎schemas/webpackOptionsSchema.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,10 @@
762762
"maxAssetSize": {
763763
"description": "Filesize limit (in bytes) when exceeded, that webpack will provide performance hints",
764764
"type": "number"
765+
},
766+
"errorOnHint": {
767+
"description": "Throw errors instead of warnings when performance hints are found",
768+
"type": "boolean"
765769
}
766770
},
767771
"type": "object"

‎test/WatchDetection.test.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*globals describe it before after */
12
var should = require("should");
23
var path = require("path");
34
var fs = require("fs");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "a";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "b";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require.ensure(["./d", "./e"], function(require) {});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "d";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "e";
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Hash: <CLR=BOLD>c45568f88684e80dbde5</CLR>
2+
Time: <CLR=BOLD>X</CLR>ms
3+
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=BOLD>Chunk Names</CLR>
4+
<CLR=32,BOLD>0.js</CLR> 227 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
5+
<CLR=32,BOLD>1.js</CLR> 100 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
6+
<CLR=32,BOLD>2.js</CLR> 178 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
7+
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>419 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> main
8+
chunk {<CLR=33,BOLD>0</CLR>} <CLR=32,BOLD>0.js</CLR> 54 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [rendered]</CLR>
9+
[5] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance-opt-in-errors/c.js</CLR> 54 bytes {<CLR=33,BOLD>0</CLR>}<CLR=32,BOLD> [built]</CLR>
10+
chunk {<CLR=33,BOLD>1</CLR>} <CLR=32,BOLD>1.js</CLR> 22 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [rendered]</CLR>
11+
[4] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance-opt-in-errors/b.js</CLR> 22 bytes {<CLR=33,BOLD>1</CLR>}<CLR=32,BOLD> [built]</CLR>
12+
chunk {<CLR=33,BOLD>2</CLR>} <CLR=32,BOLD>2.js</CLR> 44 bytes {<CLR=33,BOLD>0</CLR>}<CLR=32,BOLD> [rendered]</CLR>
13+
[6] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance-opt-in-errors/d.js</CLR> 22 bytes {<CLR=33,BOLD>2</CLR>}<CLR=32,BOLD> [built]</CLR>
14+
[7] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance-opt-in-errors/e.js</CLR> 22 bytes {<CLR=33,BOLD>2</CLR>}<CLR=32,BOLD> [built]</CLR>
15+
chunk {<CLR=33,BOLD>3</CLR>} <CLR=32,BOLD>main.js</CLR> (main) 413 kB<CLR=33,BOLD> [entry]</CLR><CLR=32,BOLD> [rendered]</CLR>
16+
[0] <CLR=BOLD>(webpack)/buildin/global.js</CLR> 487 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
17+
[1] <CLR=BOLD>(webpack)/buildin/module.js</CLR> 528 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
18+
[2] <CLR=BOLD>(webpack)/~/lodash/index.js</CLR> 411 kB {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
19+
[3] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance-opt-in-errors/a.js</CLR> 22 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
20+
[8] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance-opt-in-errors/index.js</CLR> 93 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
21+
22+
<CLR=31,BOLD>ERROR in asset size limit: The following assets exceed the recommended size limit (300 kB).
23+
This can impact web performance.
24+
Assets:
25+
main.js</CLR>
26+
27+
<CLR=31,BOLD>ERROR in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (300 kB). This can impact web performance.
28+
Entrypoints:
29+
30+
main: 419 kB
31+
main.js: 419 kB
32+
</CLR>

0 commit comments

Comments
 (0)