CacheEffectivenessWarning.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Alexander Akait @alexander-akait
  4. */
  5. "use strict";
  6. const WebpackError = require("./WebpackError");
  7. /**
  8. * @typedef {object} CacheEffectiveness
  9. * @property {number} total how many modules the compilation holds
  10. * @property {number} rebuilt how many of them were built rather than reused
  11. * @property {number} uncacheable how many can never be reused
  12. * @property {string[]} reasons why they cannot, most frequent first
  13. */
  14. class CacheEffectivenessWarning extends WebpackError {
  15. /**
  16. * Creates an instance of CacheEffectivenessWarning.
  17. * @param {CacheEffectiveness} effectiveness what the compilation reused
  18. */
  19. constructor({ total, rebuilt, uncacheable, reasons }) {
  20. const lines = [];
  21. // Only stated when something was reused, which is what proves the cache was
  22. // warm — a cold build rebuilds everything by design.
  23. if (rebuilt < total) {
  24. lines.push(
  25. `${rebuilt} of ${total} modules were rebuilt although the cache was warm.`
  26. );
  27. }
  28. if (uncacheable > 0) {
  29. lines.push(
  30. `${uncacheable} ${
  31. uncacheable === 1 ? "module is" : "modules are"
  32. } not cacheable, so ${
  33. uncacheable === 1 ? "it rebuilds" : "they rebuild"
  34. } on every build: ${reasons.join(", ")}.`
  35. );
  36. }
  37. super(
  38. `module caching: ${lines.join(
  39. " "
  40. )}\nA loader calling 'this.cacheable(false)', or a value that changes every build, prevents reuse. Stats list the modules individually as '[not cacheable]'.\nFor more info visit https://webpack.js.org/configuration/cache/`
  41. );
  42. /** @type {string} */
  43. this.name = "CacheEffectivenessWarning";
  44. }
  45. }
  46. module.exports = CacheEffectivenessWarning;