feat(vite): support node integration in renderers#4317
Open
tzh476 wants to merge 1 commit into
Open
Conversation
Co-authored-by: rafael81 <36774+rafael81@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3961.
This follows up on #4258 and keeps its renderer-level
nodeIntegrationAPI. @rafael81 is retained as a co-author.Why externalization is not enough
While validating #4258 in Electron, I found that externalizing Electron and Node.js built-ins leaves bare ESM imports in the renderer output. Vite loads that output as a browser module, which fails before application code runs:
The development server similarly resolves Node.js modules to Vite browser-external stubs.
What changed
renderer[].nodeIntegrationsettingfs-extracan augment Node.js modulesThe runtime-shim approach follows the model proven by
vite-plugin-electron-renderer,implemented here only for built-ins so Forge does not gain another runtime
dependency.
Security boundary
This option only configures Vite. The corresponding
BrowserWindowmust usenodeIntegration: trueandcontextIsolation: false. It should only load trusted local content; a preload script withcontextBridgeremains the safer default.Validation
I also ran an Electron 39.2.6 / Vite 6.4.3 smoke fixture against the compiled Forge plugin in both development-server and production-build modes. It exercised default, named, namespace, side-effect, and dynamic built-in imports plus a transitive
fs-extraCommonJS dependency; both modes delivered the expected IPC result.