PlatformPlugin.js 928 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. * @param {Partial<PlatformTargetProperties>} platform target properties
  16. */
  17. constructor(platform) {
  18. /** @type {Partial<PlatformTargetProperties>} */
  19. this.platform = platform;
  20. }
  21. /**
  22. * Apply the plugin
  23. * @param {Compiler} compiler the compiler instance
  24. * @returns {void}
  25. */
  26. apply(compiler) {
  27. compiler.hooks.environment.tap(PLUGIN_NAME, () => {
  28. compiler.platform = {
  29. ...compiler.platform,
  30. ...this.platform
  31. };
  32. });
  33. }
  34. }
  35. module.exports = PlatformPlugin;