PlatformPlugin.js 1015 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. const PLUGIN_NAME = "PlatformPlugin";
  9. /**
  10. * Should be used only for "target === false" or
  11. * when you want to overwrite platform target properties
  12. */
  13. class PlatformPlugin {
  14. /**
  15. * Creates an instance of PlatformPlugin.
  16. * @param {Partial<PlatformTargetProperties>} platform target properties
  17. */
  18. constructor(platform) {
  19. /** @type {Partial<PlatformTargetProperties>} */
  20. this.platform = platform;
  21. }
  22. /**
  23. * Applies the plugin by registering its hooks on the compiler.
  24. * @param {Compiler} compiler the compiler instance
  25. * @returns {void}
  26. */
  27. apply(compiler) {
  28. compiler.hooks.environment.tap(PLUGIN_NAME, () => {
  29. compiler.platform = {
  30. ...compiler.platform,
  31. ...this.platform
  32. };
  33. });
  34. }
  35. }
  36. module.exports = PlatformPlugin;