Skip to content

Commit 0f0bdff

Browse files
TheLarkInnsokra
authored andcommitted
fix(syntax): fixed edge case where assets do not exist, and added schema
1 parent 2741098 commit 0f0bdff

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

lib/WebpackOptionsDefaulter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ function WebpackOptionsDefaulter() {
1313
this.set("context", process.cwd());
1414
this.set("target", "web");
1515

16-
this.set("performance.maxAssetSize", 250);
16+
this.set("performance.maxInitialChunkSize", 300);
17+
this.set("performance.maxAssetSize", 300);
1718
this.set("performance.hints", true);
1819

1920
this.set("module.unknownContextRequest", ".");

lib/performance/EmittedAssetSizeLimitPlugin.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var path = require('path');
66

77
function EmittedAssetSizeLimitPlugin(performanceOptions) {
88
this.maxAssetSize = performanceOptions.maxAssetSize;
9+
this.maxInitialSize = performanceOptions.maxInitialChunkSize;
910
this.hints = performanceOptions.hints;
1011
}
1112

@@ -44,6 +45,7 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
4445
return;
4546
}
4647

48+
var totalInitialChunkSize = this.maxInitialSize;
4749
var sizeLimit = this.maxAssetSize;
4850
var hints = this.hints;
4951
var jsRegex = /\.js($|\?)/i;
@@ -52,9 +54,8 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
5254
debugger;
5355
var assets = Object.keys(compilation.assets);
5456
var noOfAssets = assets.length;
55-
var warnings = null;
56-
var initialLimit = 300;
57-
var totalInitialCost = 0;
57+
var warnings = [];
58+
var actualTotalInitialSize = 0;
5859

5960
assets.forEach(function(file) {
6061
var assetSize = compilation.assets[file].size();
@@ -63,15 +64,15 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
6364
for(var chunkKey in assetsByChunks) {
6465
var chunk = assetsByChunks[chunkKey];
6566

66-
totalInitialCost += chunk.size;
67+
actualTotalInitialSize += chunk.size;
6768
}
6869

69-
warnings = jsRegex.test(file) && getJSWarnings(noOfAssets, sizeLimit, assetSize, initialLimit, totalInitialCost);
70+
warnings = jsRegex.test(file) && getJSWarnings(noOfAssets, sizeLimit, assetSize);
7071
});
7172

72-
if(doesExceedInitialLimit(initialLimit, totalInitialCost)) {
73+
if(doesExceedInitialLimit(totalInitialChunkSize, actualTotalInitialSize)) {
7374
//TODO# Maybe separate warning name
74-
warnings.push(new Error("EmittedAssetSizeWarning: " + "The total initial download cost for these assets are likey to impact web performance. Consider keeping the total size of your initial assets < " + initialLimit + "kB"));
75+
warnings.push(new Error("EmittedAssetSizeWarning: " + "The total initial download cost for these assets are likey to impact web performance. Consider keeping the total size of your initial assets < " + totalInitialChunkSize + "kB"));
7576
}
7677

7778
if(warnings.length > 0) {

schemas/webpackOptionsSchema.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,13 +751,17 @@
751751
"description": "Configuration for web performance recommendations.",
752752
"additionalProperties": false,
753753
"properties": {
754-
"maxAssetSize": {
755-
"description": "Filesize limit (in kB) when exceeded, that webpack will provide performance hints",
756-
"type": "number"
757-
},
758754
"hints": {
759755
"description": "Turn hints on or off",
760756
"type": "boolean"
757+
},
758+
"maxInitialChunkSize": {
759+
"description": "Total size of all initial chunks (in kb)",
760+
"type": "number"
761+
},
762+
"maxAssetSize": {
763+
"description": "Filesize limit (in kB) when exceeded, that webpack will provide performance hints",
764+
"type": "number"
761765
}
762766
},
763767
"type": "object"

0 commit comments

Comments
 (0)