UnsplitVendorsWarning.js 1.3 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} UnsplitVendorChunkDetails
  10. * @property {string} name
  11. * @property {number} vendorModules how many of its modules come from node_modules
  12. * @property {number} vendorSize bytes those modules contribute
  13. */
  14. class UnsplitVendorsWarning extends WebpackError {
  15. /**
  16. * Creates an instance of UnsplitVendorsWarning.
  17. * @param {UnsplitVendorChunkDetails[]} chunks the worst offenders, largest vendor size first
  18. */
  19. constructor(chunks) {
  20. const list = chunks
  21. .map(
  22. (chunk) =>
  23. `\n ${chunk.name} (${chunk.vendorModules} modules from node_modules, ${formatSize(
  24. chunk.vendorSize
  25. )})`
  26. )
  27. .join("");
  28. super(
  29. `unsplit vendors: initial chunks carry node_modules code next to application code:${list}\nThe dependencies then get a new hash on every application change, so returning visitors download them again. 'optimization.splitChunks' can move them into a chunk of their own.\nFor more info visit https://webpack.js.org/plugins/split-chunks-plugin/`
  30. );
  31. /** @type {string} */
  32. this.name = "UnsplitVendorsWarning";
  33. }
  34. }
  35. module.exports = UnsplitVendorsWarning;