ElectronTargetPlugin.js 1.5 KB

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