forge icon indicating copy to clipboard operation
forge copied to clipboard

Vite plugin: support `nodeIntegration: true` in the renderer process.

Open hab25 opened this issue 5 months ago • 3 comments

Pre-flight checklist

  • [x] I have read the contribution documentation for this project.
  • [x] I agree to follow the code of conduct that this project uses.
  • [x] I have searched the issue tracker for a feature request that matches the one I want to file, without success.

Problem description

When using the electron forge vite plugin, configuring vite for nodeIntegration: true in the renderer process requires too much of vite-specific knowledge and configuration. Further, even if one makes it work, there is no guarantee that it won't break on future updates of the plugin since it such configuration could interfering with internal assumptions of the plugin.

Proposed solution

Something like the webpack plugin does for this use case. See https://github.com/electron-forge/electron-forge-docs/blob/f83f6237a6e0018c426a1b7efddc8098eca2c01c/config/plugins/webpack.md?plain=1#L269 .

Alternatives considered

  • fragile "Manual" vite configuration as described above.
  • shifting a lot of what would be in the renderer into the preload script (incurs more boilerplate and complexity).

Additional information

No response

hab25 avatar Jul 11 '25 21:07 hab25

@erickzhao @dsanders11 Hi, I would like to work on this enhancement feature, I have been reading the documentation and found that plugin-vite is experimental, there should a nodeIntegration option for vite plugin same as webpack plugin, this would be a great enhancement for the plugin.

My proposed plan is to: Add a nodeIntegration option to the Vite plugin's configuration, just like the Webpack plugin has. When this option is true, I will update the Vite config to mark all of Node.js's built-in modules (like 'fs', 'path', etc.) as "external". This will tell Vite not to bundle them, which should achieve the goal.

This will ensure Vite avoids bundling these modules, aligning the behavior with expected Node.js runtime

Does this sound like the right technical approach? I'm ready to start working on a PR if this aligns with the project's goals. Thank you!.

RNAdvani avatar Jul 22 '25 07:07 RNAdvani

@hab25 can u provide me config if you have found a solution to make it work with nodeIntegration:true

RNAdvani avatar Aug 14 '25 14:08 RNAdvani

@RNAdvani I haven't found one, so I'm using preload.

hab25 avatar Aug 14 '25 23:08 hab25