ElectronTargetPlugin.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ExternalsPlugin = require("../ExternalsPlugin");
  7. /** @typedef {import("../Compiler")} Compiler */
  8. class ElectronTargetPlugin {
  9. /**
  10. * @param {"main" | "preload" | "renderer"=} context in main, preload or renderer context?
  11. */
  12. constructor(context) {
  13. this._context = context;
  14. }
  15. /**
  16. * Apply the plugin
  17. * @param {Compiler} compiler the compiler instance
  18. * @returns {void}
  19. */
  20. apply(compiler) {
  21. new ExternalsPlugin("node-commonjs", [
  22. "clipboard",
  23. "crash-reporter",
  24. "electron",
  25. "ipc",
  26. "native-image",
  27. "original-fs",
  28. "screen",
  29. "shell"
  30. ]).apply(compiler);
  31. switch (this._context) {
  32. case "main":
  33. new ExternalsPlugin("node-commonjs", [
  34. "app",
  35. "auto-updater",
  36. "browser-window",
  37. "content-tracing",
  38. "dialog",
  39. "global-shortcut",
  40. "ipc-main",
  41. "menu",
  42. "menu-item",
  43. "power-monitor",
  44. "power-save-blocker",
  45. "protocol",
  46. "session",
  47. "tray",
  48. "web-contents"
  49. ]).apply(compiler);
  50. break;
  51. case "preload":
  52. case "renderer":
  53. new ExternalsPlugin("node-commonjs", [
  54. "desktop-capturer",
  55. "ipc-renderer",
  56. "remote",
  57. "web-frame"
  58. ]).apply(compiler);
  59. break;
  60. }
  61. }
  62. }
  63. module.exports = ElectronTargetPlugin;