LegacyJavascriptWarning.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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} LegacyPackageDetails
  10. * @property {string} name the package doing the emulating
  11. * @property {number} modules how many of its modules are in the build
  12. * @property {number} size bytes they contribute
  13. */
  14. class LegacyJavascriptWarning extends WebpackError {
  15. /**
  16. * Creates an instance of LegacyJavascriptWarning.
  17. * @param {LegacyPackageDetails[]} packages the ones found, largest first
  18. * @param {number} totalSize bytes they contribute between them
  19. * @param {string[]} features the ones the target already has
  20. */
  21. constructor(packages, totalSize, features) {
  22. const list = packages
  23. .map(
  24. (item) =>
  25. `\n ${item.name} (${item.modules} ${
  26. item.modules === 1 ? "module" : "modules"
  27. }, ${formatSize(item.size)})`
  28. )
  29. .join("");
  30. super(
  31. `legacy javascript: ${formatSize(
  32. totalSize
  33. )} of the build emulates syntax the target already has natively:${list}\n'output.environment' says this target supports ${features.join(
  34. ", "
  35. )}, so whatever lowers the syntax — usually '@babel/preset-env' — is compiling for older browsers than webpack is. Lining its targets up with the browserslist webpack reads drops them.\nFor more info visit https://webpack.js.org/configuration/target/#browserslist`
  36. );
  37. /** @type {string} */
  38. this.name = "LegacyJavascriptWarning";
  39. }
  40. }
  41. module.exports = LegacyJavascriptWarning;