TinyChunksWarning.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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} TinyChunkDetails
  10. * @property {string} name the chunk, by name or by id
  11. * @property {number} size bytes it carries
  12. */
  13. class TinyChunksWarning extends WebpackError {
  14. /**
  15. * Creates an instance of TinyChunksWarning.
  16. * @param {TinyChunkDetails[]} chunks the smallest of them
  17. * @param {number} total how many fall under the floor in all
  18. * @param {number} totalSize bytes they carry between them
  19. */
  20. constructor(chunks, total, totalSize) {
  21. const list = chunks
  22. .map((chunk) => `\n ${chunk.name} (${formatSize(chunk.size)})`)
  23. .join("");
  24. super(
  25. `tiny chunks: ${total} chunks are loaded on demand but carry less than 'optimization.splitChunks.minSize', ${formatSize(
  26. totalSize
  27. )} between them:${list}\nEach costs a request of its own, and that option is already the size below which webpack itself declines to make a chunk. Giving several 'import()' calls one 'webpackChunkName' groups them into a single chunk.\nFor more info visit https://webpack.js.org/api/module-methods/#magic-comments`
  28. );
  29. /** @type {string} */
  30. this.name = "TinyChunksWarning";
  31. }
  32. }
  33. module.exports = TinyChunksWarning;