UnusedReexportsWarning.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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} UnusedReexportDetails
  10. * @property {string} name
  11. * @property {number} size bytes the module costs
  12. */
  13. class UnusedReexportsWarning extends WebpackError {
  14. /**
  15. * Creates an instance of UnusedReexportsWarning.
  16. * @param {UnusedReexportDetails[]} modules the worst offenders, largest first
  17. * @param {number} total how many modules are bundled unused
  18. * @param {number} wasted bytes they cost together
  19. */
  20. constructor(modules, total, wasted) {
  21. const list = modules
  22. .map((module) => `\n ${module.name} (${formatSize(module.size)})`)
  23. .join("");
  24. super(
  25. `unused re-exports: ${total} ${
  26. total === 1 ? "module is" : "modules are"
  27. } bundled although nothing uses what they export, adding ${formatSize(
  28. wasted
  29. )}:${list}\nA module you import re-exports them, and their top-level code has side effects webpack is not allowed to drop. Setting '"sideEffects": false' in the package.json that owns them lets webpack leave them out.\nFor more info visit https://webpack.js.org/guides/tree-shaking/`
  30. );
  31. /** @type {string} */
  32. this.name = "UnusedReexportsWarning";
  33. }
  34. }
  35. module.exports = UnusedReexportsWarning;