vite: let a framework build an environment in another process
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- node.js, typescript, vite
- Domain
- backend, build-system
Research direction
Start by reading src/build/vite/prod.ts, especially buildEnvironments, then inspect src/build/vite/plugin.ts around nitro:prepare. Trace when Nitro reads client output and cleans the output directory; the issue is done when a framework can await an external environment build and avoid cleanup in a client-only process, while the default build remains serial.
Written by the indexing model from the issue text.
Description
I tried building the client in a second process while the main process builds SSR, on a Nuxt 5 app. On a big test app (12 layers, about 2,900 components) a clean build went from about 35 s to 23.5 s, with the same output file for file. On a real app it saved about 8 s of 140 s, because Nitro's own build was most of that build there.
Two processes are needed. With Promise.all in one process the build wasn't faster (37.5 s), because each build keeps the JS thread busy about 90% of the time.
Most of this works today. A framework sets builder.environments.client.isBuilt = true in a buildApp hook before Nitro's and builds the client somewhere else. Nitro then skips it. But Nitro assumes isBuilt means the files are already on disk:
- Right after the loop in
buildEnvironments, Nitro reads the client'sindex.htmlfor the renderer template, callswriteAssetsManifest, copies public assets and builds the server. Nothing waits for the other process. In my Nuxt test it only works because Nuxt's SSRgenerateBundlehappens to wait for the client. nitro:preparecleans the output directory in every process that runs Nitro's plugin. The second process has to avoid it, or it can delete what the main process already wrote.
Some ideas, up to you:
- A way to register a pending build that
buildEnvironmentsawaits before it goes on.isBuiltcould accept a promise, or there could be a hook a framework can await in. - A way to skip
preparein a process that only builds a client environment.
The default should stay serial. Frameworks like Nuxt pass state between environments in memory, and in one process it doesn't help anyway.
I haven't proposed the Nuxt side yet, so this is early. If you'd rather wait until a framework actually needs it, that's fine.
Related: the Vite guide shows Promise.all in buildApp, sapphi-red's note that plugin workarounds "won't work when all envs are built concurrently" in vitejs/vite#16358, and hi-ogawa/vite-plugins#350, an open WIP that builds browser and server in parallel.
Versions: Nitro 3.0.260903-beta (same code on main at f794c378), Vite 8.3.5, Rolldown 1.2.15, Node 24.
- Dominant language
- TypeScript
- Stars
- 11.5k
- Forks
- 968
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 64
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nitrojs/nitro
-
pending triage
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 2 days
-
cloudflare: `nitro deploy` fails when a parent directory has a Wrangler configPossibly taken @draarivpatel-ui claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 2 days
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
pending triage
Difficulty 5/5 Over a week Newbie friendliness 30/100
nitrojs/nitro#5205 · 1 reaction ·
Maintainers usually reply within 2 days
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ranxianglei/billion-context#8319 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JimLiu/open-artifact#126 ·
-
bug repro-ready
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
mksglu/context-mode#1454 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
laststance/design-world#98 ·
Maintainers usually reply within 1 day
-
Add: KCM True crimeOpenapproved check:passed streams:add
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day