InlinedAssetsWarning.js 1.2 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} InlinedAssetDetails
  9. * @property {string} name the asset, by path
  10. * @property {number} size the bytes it adds to the JavaScript
  11. */
  12. class InlinedAssetsWarning extends WebpackError {
  13. /**
  14. * Creates an instance of InlinedAssetsWarning.
  15. * @param {InlinedAssetDetails[]} assets the assets inlined as data urls
  16. * @param {number} total the bytes they add between them
  17. */
  18. constructor(assets, total) {
  19. const list = assets
  20. .map((it) => `\n ${it.name} (${it.size} bytes)`)
  21. .join("");
  22. super(
  23. `inlined assets: ${total} bytes of asset data are embedded in the JavaScript:${list}\nA data url is base64, so it costs about a third more than the file it replaces, cannot be cached on its own, and is downloaded again whenever the code around it changes. 'Rule.parser.dataUrlCondition.maxSize' decides which files are small enough to be worth that.\nFor more info visit https://webpack.js.org/guides/asset-modules/#general-asset-type`
  24. );
  25. /** @type {string} */
  26. this.name = "InlinedAssetsWarning";
  27. }
  28. }
  29. module.exports = InlinedAssetsWarning;