feat(plugin-vite): run main/preload dev builds in subprocess workers#4226
Merged
feat(plugin-vite): run main/preload dev builds in subprocess workers#4226
Conversation
…kers
Dev-mode (`electron-forge start`) main and preload builds now run in the
same subprocess worker used for production builds, instead of calling
`vite.build()` in-process.
The worker gains a watch mode gated on `FORGE_VITE_WATCH=1`: it signals
first-build completion/error over IPC and logs subsequent rebuild events
itself. Two bits of cross-process state are bridged explicitly:
- `*_VITE_DEV_SERVER_URL` defines: the parent passes the renderer dev
server URL map via `FORGE_VITE_DEV_SERVER_URLS` and the worker seeds
the module-level `viteDevServerUrls` before resolving the config.
- Preload hot-reload: the worker sends a `reload-renderers` IPC message
on `closeBundle` and the parent fans out `ws.send({type:'full-reload'})`
to the in-process renderer dev servers.
The plugin tracks watch child processes instead of `RollupWatcher`
instances and `exitHandler` kills them on shutdown.
erickzhao
reviewed
Apr 20, 2026
erickzhao
approved these changes
Apr 21, 2026
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.
Summary
start) Vite builds in the existing subprocess worker instead of in-process, matching the production build path.FORGE_VITE_WATCH=1mode: IPCfirst-build-done/first-build-errorto resolve the Listr task, and the worker prints rebuild/error log lines itself with the same formatting as before.getBuildDefineruns) and preload → renderer hot-reload (IPCreload-renderers→ parent callsserver.ws.send({type:'full-reload'})).VitePluginnow tracksChildProcess[]instead ofRollupWatcher[];exitHandlerkills children. Net −47 lines inVitePlugin.ts.Renderer dev servers remain in-process for now (port/URL handshake is a larger change).
Test plan
yarn build/tsc --noEmitcleanyarn vitest run packages/plugin/vite/spec/— 22/22 passyarn lint:js— 0 errorsFORGE_VITE_DEV_SERVER_URLSlands in the bundled output as the*_VITE_DEV_SERVER_URLdefinereload-renderers, main does notfirst-build-errorwith no trailingfirst-build-doneelectron-forge startagainst a real Vite app (smoke-tested locally via patchednode_modules, looks good)