Skip to content

feat(plugin-vite): run main/preload dev builds in subprocess workers#4226

Merged
erickzhao merged 2 commits intonextfrom
sam/vite-dev-watch-workers
Apr 21, 2026
Merged

feat(plugin-vite): run main/preload dev builds in subprocess workers#4226
erickzhao merged 2 commits intonextfrom
sam/vite-dev-watch-workers

Conversation

@MarshallOfSound
Copy link
Copy Markdown
Member

@MarshallOfSound MarshallOfSound commented Apr 18, 2026

Summary

  • Run main/preload dev-mode (start) Vite builds in the existing subprocess worker instead of in-process, matching the production build path.
  • Worker gains a FORGE_VITE_WATCH=1 mode: IPC first-build-done / first-build-error to resolve the Listr task, and the worker prints rebuild/error log lines itself with the same formatting as before.
  • Bridge the two bits of in-process shared state the old path relied on: the renderer dev-server URL map (passed via env and seeded before getBuildDefine runs) and preload → renderer hot-reload (IPC reload-renderers → parent calls server.ws.send({type:'full-reload'})).
  • VitePlugin now tracks ChildProcess[] instead of RollupWatcher[]; exitHandler kills children. Net −47 lines in VitePlugin.ts.

Renderer dev servers remain in-process for now (port/URL handshake is a larger change).

Test plan

  • yarn build / tsc --noEmit clean
  • yarn vitest run packages/plugin/vite/spec/ — 22/22 pass
  • yarn lint:js — 0 errors
  • Worker harness: seeded FORGE_VITE_DEV_SERVER_URLS lands in the bundled output as the *_VITE_DEV_SERVER_URL define
  • Worker harness: preload target emits reload-renderers, main does not
  • Worker harness: broken entry → first-build-error with no trailing first-build-done
  • Manual electron-forge start against a real Vite app (smoke-tested locally via patched node_modules, looks good)

…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.
@MarshallOfSound MarshallOfSound requested a review from a team as a code owner April 18, 2026 02:47
@github-actions github-actions Bot added the next label Apr 18, 2026
Comment thread packages/plugin/vite/src/subprocess-worker.ts
@erickzhao erickzhao merged commit eeb71e6 into next Apr 21, 2026
12 checks passed
@erickzhao erickzhao deleted the sam/vite-dev-watch-workers branch April 21, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants