diff options
Diffstat (limited to 'node_modules/webpack/lib/performance')
4 files changed, 186 insertions, 173 deletions
diff --git a/node_modules/webpack/lib/performance/AssetsOverSizeLimitWarning.js b/node_modules/webpack/lib/performance/AssetsOverSizeLimitWarning.js index 17a5112d8..aac8b65a9 100644 --- a/node_modules/webpack/lib/performance/AssetsOverSizeLimitWarning.js +++ b/node_modules/webpack/lib/performance/AssetsOverSizeLimitWarning.js @@ -1,23 +1,30 @@ -/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Sean Larkin @thelarkinn
-*/
-"use strict";
-
-const WebpackError = require("../WebpackError");
-const SizeFormatHelpers = require("../SizeFormatHelpers");
-
-module.exports = class AssetsOverSizeLimitWarning extends WebpackError {
- constructor(assetsOverSizeLimit, assetLimit) {
- super();
-
- this.name = "AssetsOverSizeLimitWarning";
- this.assets = assetsOverSizeLimit;
- const assetLists = this.assets.map(asset => `\n ${asset.name} (${SizeFormatHelpers.formatSize(asset.size)})`).join("");
- this.message = `asset size limit: The following asset(s) exceed the recommended size limit (${SizeFormatHelpers.formatSize(assetLimit)}).
-This can impact web performance.
-Assets: ${assetLists}`;
-
- Error.captureStackTrace(this, this.constructor);
- }
-};
+/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Sean Larkin @thelarkinn +*/ +"use strict"; + +const WebpackError = require("../WebpackError"); +const SizeFormatHelpers = require("../SizeFormatHelpers"); + +module.exports = class AssetsOverSizeLimitWarning extends WebpackError { + constructor(assetsOverSizeLimit, assetLimit) { + const assetLists = assetsOverSizeLimit + .map( + asset => + `\n ${asset.name} (${SizeFormatHelpers.formatSize(asset.size)})` + ) + .join(""); + + super(`asset size limit: The following asset(s) exceed the recommended size limit (${SizeFormatHelpers.formatSize( + assetLimit + )}). +This can impact web performance. +Assets: ${assetLists}`); + + this.name = "AssetsOverSizeLimitWarning"; + this.assets = assetsOverSizeLimit; + + Error.captureStackTrace(this, this.constructor); + } +}; diff --git a/node_modules/webpack/lib/performance/EntrypointsOverSizeLimitWarning.js b/node_modules/webpack/lib/performance/EntrypointsOverSizeLimitWarning.js index 9fb2de104..3c29553d2 100644 --- a/node_modules/webpack/lib/performance/EntrypointsOverSizeLimitWarning.js +++ b/node_modules/webpack/lib/performance/EntrypointsOverSizeLimitWarning.js @@ -1,28 +1,30 @@ -/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Sean Larkin @thelarkinn
-*/
-"use strict";
-
-const WebpackError = require("../WebpackError");
-const SizeFormatHelpers = require("../SizeFormatHelpers");
-
-module.exports = class EntrypointsOverSizeLimitWarning extends WebpackError {
- constructor(entrypoints, entrypointLimit) {
- super();
-
- this.name = "EntrypointsOverSizeLimitWarning";
- this.entrypoints = entrypoints;
- const entrypointList = this.entrypoints.map(entrypoint => `\n ${
- entrypoint.name
- } (${
- SizeFormatHelpers.formatSize(entrypoint.size)
- })\n${
- entrypoint.files.map(asset => ` ${asset}`).join("\n")
- }`).join("");
- this.message = `entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (${SizeFormatHelpers.formatSize(entrypointLimit)}). This can impact web performance.
-Entrypoints:${entrypointList}\n`;
-
- Error.captureStackTrace(this, this.constructor);
- }
-};
+/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Sean Larkin @thelarkinn +*/ +"use strict"; + +const WebpackError = require("../WebpackError"); +const SizeFormatHelpers = require("../SizeFormatHelpers"); + +module.exports = class EntrypointsOverSizeLimitWarning extends WebpackError { + constructor(entrypoints, entrypointLimit) { + const entrypointList = entrypoints + .map( + entrypoint => + `\n ${entrypoint.name} (${SizeFormatHelpers.formatSize( + entrypoint.size + )})\n${entrypoint.files.map(asset => ` ${asset}`).join("\n")}` + ) + .join(""); + super(`entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (${SizeFormatHelpers.formatSize( + entrypointLimit + )}). This can impact web performance. +Entrypoints:${entrypointList}\n`); + + this.name = "EntrypointsOverSizeLimitWarning"; + this.entrypoints = entrypoints; + + Error.captureStackTrace(this, this.constructor); + } +}; diff --git a/node_modules/webpack/lib/performance/NoAsyncChunksWarning.js b/node_modules/webpack/lib/performance/NoAsyncChunksWarning.js index 2ca7c35b9..c64475f97 100644 --- a/node_modules/webpack/lib/performance/NoAsyncChunksWarning.js +++ b/node_modules/webpack/lib/performance/NoAsyncChunksWarning.js @@ -1,20 +1,21 @@ -/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Sean Larkin @thelarkinn
-*/
-"use strict";
-
-const WebpackError = require("../WebpackError");
-
-module.exports = class NoAsyncChunksWarning extends WebpackError {
- constructor() {
- super();
-
- this.name = "NoAsyncChunksWarning";
- this.message = "webpack performance recommendations: \n" +
- "You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.\n" +
- "For more info visit https://webpack.js.org/guides/code-splitting/";
-
- Error.captureStackTrace(this, this.constructor);
- }
-};
+/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Sean Larkin @thelarkinn +*/ +"use strict"; + +const WebpackError = require("../WebpackError"); + +module.exports = class NoAsyncChunksWarning extends WebpackError { + constructor() { + super( + "webpack performance recommendations: \n" + + "You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.\n" + + "For more info visit https://webpack.js.org/guides/code-splitting/" + ); + + this.name = "NoAsyncChunksWarning"; + + Error.captureStackTrace(this, this.constructor); + } +}; diff --git a/node_modules/webpack/lib/performance/SizeLimitsPlugin.js b/node_modules/webpack/lib/performance/SizeLimitsPlugin.js index e97b3b368..93b43651f 100644 --- a/node_modules/webpack/lib/performance/SizeLimitsPlugin.js +++ b/node_modules/webpack/lib/performance/SizeLimitsPlugin.js @@ -1,102 +1,105 @@ -/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Sean Larkin @thelarkinn
-*/
-"use strict";
-const EntrypointsOverSizeLimitWarning = require("./EntrypointsOverSizeLimitWarning");
-const AssetsOverSizeLimitWarning = require("./AssetsOverSizeLimitWarning");
-const NoAsyncChunksWarning = require("./NoAsyncChunksWarning");
-
-module.exports = class SizeLimitsPlugin {
- constructor(options) {
- this.hints = options.hints;
- this.maxAssetSize = options.maxAssetSize;
- this.maxEntrypointSize = options.maxEntrypointSize;
- this.assetFilter = options.assetFilter;
- }
- apply(compiler) {
- const entrypointSizeLimit = this.maxEntrypointSize;
- const assetSizeLimit = this.maxAssetSize;
- const hints = this.hints;
- const assetFilter = this.assetFilter || (asset => !(/\.map$/.test(asset)));
-
- compiler.plugin("after-emit", (compilation, callback) => {
- const warnings = [];
-
- const getEntrypointSize = entrypoint =>
- entrypoint.getFiles()
- .filter(assetFilter)
- .map(file => compilation.assets[file])
- .filter(Boolean)
- .map(asset => asset.size())
- .reduce((currentSize, nextSize) => currentSize + nextSize, 0);
-
- const assetsOverSizeLimit = [];
- Object.keys(compilation.assets)
- .filter(assetFilter)
- .forEach(assetName => {
- const asset = compilation.assets[assetName];
- const size = asset.size();
-
- if(size > assetSizeLimit) {
- assetsOverSizeLimit.push({
- name: assetName,
- size: size,
- });
- asset.isOverSizeLimit = true;
- }
- });
-
- const entrypointsOverLimit = [];
- Object.keys(compilation.entrypoints)
- .forEach(key => {
- const entry = compilation.entrypoints[key];
- const size = getEntrypointSize(entry, compilation);
-
- if(size > entrypointSizeLimit) {
- entrypointsOverLimit.push({
- name: key,
- size: size,
- files: entry.getFiles().filter(assetFilter)
- });
- entry.isOverSizeLimit = true;
- }
- });
-
- if(hints) {
- // 1. Individual Chunk: Size < 250kb
- // 2. Collective Initial Chunks [entrypoint] (Each Set?): Size < 250kb
- // 3. No Async Chunks
- // if !1, then 2, if !2 return
- if(assetsOverSizeLimit.length > 0) {
- warnings.push(
- new AssetsOverSizeLimitWarning(
- assetsOverSizeLimit,
- assetSizeLimit));
- }
- if(entrypointsOverLimit.length > 0) {
- warnings.push(
- new EntrypointsOverSizeLimitWarning(
- entrypointsOverLimit,
- entrypointSizeLimit));
- }
-
- if(warnings.length > 0) {
- const hasAsyncChunks = compilation.chunks.filter(chunk => !chunk.isInitial()).length > 0;
-
- if(!hasAsyncChunks) {
- warnings.push(new NoAsyncChunksWarning());
- }
-
- if(hints === "error") {
- Array.prototype.push.apply(compilation.errors, warnings);
- } else {
- Array.prototype.push.apply(compilation.warnings, warnings);
- }
- }
- }
-
- callback();
- });
- }
-};
+/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Sean Larkin @thelarkinn +*/ +"use strict"; +const EntrypointsOverSizeLimitWarning = require("./EntrypointsOverSizeLimitWarning"); +const AssetsOverSizeLimitWarning = require("./AssetsOverSizeLimitWarning"); +const NoAsyncChunksWarning = require("./NoAsyncChunksWarning"); + +module.exports = class SizeLimitsPlugin { + constructor(options) { + this.hints = options.hints; + this.maxAssetSize = options.maxAssetSize; + this.maxEntrypointSize = options.maxEntrypointSize; + this.assetFilter = options.assetFilter; + } + apply(compiler) { + const entrypointSizeLimit = this.maxEntrypointSize; + const assetSizeLimit = this.maxAssetSize; + const hints = this.hints; + const assetFilter = this.assetFilter || (asset => !asset.endsWith(".map")); + + compiler.hooks.afterEmit.tap("SizeLimitsPlugin", compilation => { + const warnings = []; + + const getEntrypointSize = entrypoint => + entrypoint.getFiles().reduce((currentSize, file) => { + if (assetFilter(file) && compilation.assets[file]) { + return currentSize + compilation.assets[file].size(); + } + + return currentSize; + }, 0); + + const assetsOverSizeLimit = []; + for (const assetName of Object.keys(compilation.assets)) { + if (!assetFilter(assetName)) { + continue; + } + + const asset = compilation.assets[assetName]; + const size = asset.size(); + if (size > assetSizeLimit) { + assetsOverSizeLimit.push({ + name: assetName, + size: size + }); + asset.isOverSizeLimit = true; + } + } + + const entrypointsOverLimit = []; + for (const pair of compilation.entrypoints) { + const name = pair[0]; + const entry = pair[1]; + const size = getEntrypointSize(entry); + + if (size > entrypointSizeLimit) { + entrypointsOverLimit.push({ + name: name, + size: size, + files: entry.getFiles().filter(assetFilter) + }); + entry.isOverSizeLimit = true; + } + } + + if (hints) { + // 1. Individual Chunk: Size < 250kb + // 2. Collective Initial Chunks [entrypoint] (Each Set?): Size < 250kb + // 3. No Async Chunks + // if !1, then 2, if !2 return + if (assetsOverSizeLimit.length > 0) { + warnings.push( + new AssetsOverSizeLimitWarning(assetsOverSizeLimit, assetSizeLimit) + ); + } + if (entrypointsOverLimit.length > 0) { + warnings.push( + new EntrypointsOverSizeLimitWarning( + entrypointsOverLimit, + entrypointSizeLimit + ) + ); + } + + if (warnings.length > 0) { + const hasAsyncChunks = + compilation.chunks.filter(chunk => !chunk.canBeInitial()).length > + 0; + + if (!hasAsyncChunks) { + warnings.push(new NoAsyncChunksWarning()); + } + + if (hints === "error") { + compilation.errors.push(...warnings); + } else { + compilation.warnings.push(...warnings); + } + } + } + }); + } +}; |