AsyncChunkWaterfallWarning.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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} WaterfallDetails
  9. * @property {string[]} chain the chunk groups making up the chain, outermost first
  10. * @property {number} size the bytes the chain loads in total
  11. */
  12. class AsyncChunkWaterfallWarning extends WebpackError {
  13. /**
  14. * Creates an instance of AsyncChunkWaterfallWarning.
  15. * @param {WaterfallDetails[]} waterfalls the chains that are too deep
  16. * @param {number} depth the depth the deepest of them reaches
  17. */
  18. constructor(waterfalls, depth) {
  19. const list = waterfalls
  20. .map((it) => `\n ${it.chain.join(" → ")} (${it.size} bytes)`)
  21. .join("");
  22. super(
  23. `async chunk waterfall: ${waterfalls.length} ${waterfalls.length === 1 ? "chain loads" : "chains load"} ${depth} levels deep:${list}\nA chunk cannot be requested until the one importing it has arrived and run, so each level costs a round trip before anything below it starts. Importing the deeper modules from the entry, or giving them one 'webpackPrefetch' hint, lets them be fetched together.\nFor more info visit https://webpack.js.org/api/module-methods/#magic-comments`
  24. );
  25. /** @type {string} */
  26. this.name = "AsyncChunkWaterfallWarning";
  27. }
  28. }
  29. module.exports = AsyncChunkWaterfallWarning;