PlatformPlugin.js 894 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Authors Ivan Kopeykin @vankop
  4. */
  5. "use strict";
  6. /** @typedef {import("./Compiler")} Compiler */
  7. /** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */
  8. /**
  9. * Should be used only for "target === false" or
  10. * when you want to overwrite platform target properties
  11. */
  12. class PlatformPlugin {
  13. /**
  14. * @param {Partial<PlatformTargetProperties>} platform target properties
  15. */
  16. constructor(platform) {
  17. /** @type {Partial<PlatformTargetProperties>} */
  18. this.platform = platform;
  19. }
  20. /**
  21. * Apply the plugin
  22. * @param {Compiler} compiler the compiler instance
  23. * @returns {void}
  24. */
  25. apply(compiler) {
  26. compiler.hooks.environment.tap("PlatformPlugin", () => {
  27. compiler.platform = {
  28. ...compiler.platform,
  29. ...this.platform
  30. };
  31. });
  32. }
  33. }
  34. module.exports = PlatformPlugin;