EntrypointsOverSizeLimitWarning.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Sean Larkin @thelarkinn
  4. */
  5. "use strict";
  6. const { formatSize } = require("../SizeFormatHelpers");
  7. const WebpackError = require("../WebpackError");
  8. /** @typedef {import("./SizeLimitsPlugin").EntrypointDetails} EntrypointDetails */
  9. class EntrypointsOverSizeLimitWarning extends WebpackError {
  10. /**
  11. * Creates an instance of EntrypointsOverSizeLimitWarning.
  12. * @param {EntrypointDetails[]} entrypoints the entrypoints
  13. * @param {number} entrypointLimit the size limit
  14. */
  15. constructor(entrypoints, entrypointLimit) {
  16. const entrypointList = entrypoints
  17. .map(
  18. (entrypoint) =>
  19. `\n ${entrypoint.name} (${formatSize(
  20. entrypoint.size
  21. )})\n${entrypoint.files.map((asset) => ` ${asset}`).join("\n")}`
  22. )
  23. .join("");
  24. super(`entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (${formatSize(
  25. entrypointLimit
  26. )}). This can impact web performance.
  27. Entrypoints:${entrypointList}\n`);
  28. /** @type {string} */
  29. this.name = "EntrypointsOverSizeLimitWarning";
  30. /** @type {EntrypointDetails[]} */
  31. this.entrypoints = entrypoints;
  32. }
  33. }
  34. /** @type {typeof EntrypointsOverSizeLimitWarning} */
  35. module.exports = EntrypointsOverSizeLimitWarning;