ElectronTargetPlugin.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /** @typedef {"main" | "preload" | "renderer"} ElectronContext */
  9. class ElectronTargetPlugin {
  10. /**
  11. * @param {ElectronContext=} context in main, preload or renderer context?
  12. */
  13. constructor(context) {
  14. /** @type {ElectronContext | undefined} */
  15. this._context = context;
  16. }
  17. /**
  18. * Apply the plugin
  19. * @param {Compiler} compiler the compiler instance
  20. * @returns {void}
  21. */
  22. apply(compiler) {
  23. new ExternalsPlugin("node-commonjs", [
  24. "clipboard",
  25. "crash-reporter",
  26. "electron",
  27. "ipc",
  28. "native-image",
  29. "original-fs",
  30. "screen",
  31. "shell"
  32. ]).apply(compiler);
  33. switch (this._context) {
  34. case "main":
  35. new ExternalsPlugin("node-commonjs", [
  36. "app",
  37. "auto-updater",
  38. "browser-window",
  39. "content-tracing",
  40. "dialog",
  41. "global-shortcut",
  42. "ipc-main",
  43. "menu",
  44. "menu-item",
  45. "power-monitor",
  46. "power-save-blocker",
  47. "protocol",
  48. "session",
  49. "tray",
  50. "web-contents"
  51. ]).apply(compiler);
  52. break;
  53. case "preload":
  54. case "renderer":
  55. new ExternalsPlugin("node-commonjs", [
  56. "desktop-capturer",
  57. "ipc-renderer",
  58. "remote",
  59. "web-frame"
  60. ]).apply(compiler);
  61. break;
  62. }
  63. }
  64. }
  65. module.exports = ElectronTargetPlugin;