BroadContextsWarning.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Alexander Akait @alexander-akait
  4. */
  5. "use strict";
  6. const formatSize = require("../util/formatSize");
  7. const WebpackError = require("./WebpackError");
  8. /**
  9. * @typedef {object} BroadContextDetails
  10. * @property {string} name the context as written, shortened for the report
  11. * @property {number} modules how many distinct modules it matched
  12. * @property {number} size bytes those modules contribute
  13. */
  14. class BroadContextsWarning extends WebpackError {
  15. /**
  16. * Creates an instance of BroadContextsWarning.
  17. * @param {BroadContextDetails[]} contexts the worst offenders, largest first
  18. * @param {number} total how many broad contexts there are in all
  19. */
  20. constructor(contexts, total) {
  21. const list = contexts
  22. .map(
  23. (context) =>
  24. `\n ${context.name} (${context.modules} modules, ${formatSize(
  25. context.size
  26. )})`
  27. )
  28. .join("");
  29. super(
  30. `broad contexts: ${total} ${total === 1 ? "context matches" : "contexts match"} every file under a directory:${list}\nA pattern opening with a bare wildcard takes whatever the directory holds, including files nothing ever requests — a sync context bundles them all, a lazy one gives each its own chunk. Narrowing the pattern, or 'ContextReplacementPlugin', limits it to what is reachable.\nFor more info visit https://webpack.js.org/plugins/context-replacement-plugin/`
  31. );
  32. /** @type {string} */
  33. this.name = "BroadContextsWarning";
  34. }
  35. }
  36. module.exports = BroadContextsWarning;