vite 6 dev cold start is 41s in a 22-package workspace, deps re-optimize every reload Vite
22 packages in a pnpm workspace, one Vite app that consumes about 9 of them directly. pnpm dev from a cold dep cache takes 41 seconds to first paint, and during that it prints the "new dependencies optimized" message twice and full-page reloads each time.
Warm restart is 1.9s so the cache works, but any lockfile change or a --force and I am back to 41s. It also happens on every fresh CI preview and for anyone who just cloned the repo.
The workspace packages are consumed as source - main points at src/index.ts and Vite compiles them. That was a deliberate choice so we do not have to build 22 packages to run the app, and I would rather not give it up.
Is 41s just the price of consuming source, or am I doing something obviously wrong?
@whetstone_wu · 2mo ago · 2 replies
Do the export conditions properly and you get to keep source-in-dev and built-output everywhere else:
Vite resolves the
developmentcondition in dev, so your dev server reads source and HMR works across package boundaries. Everything else - your test runner, your build, anything consuming the package from outside - getsdist. You stop needingmainto point at TypeScript, which quietly breaks a lot of tooling that expectsmainto be JavaScript.Make sure
resolve.conditionsin your Vite config has not been overridden to something that dropsdevelopment. If you have set that array yourself you probably clobbered the defaults.Reply
Report
@durable_ines · 2mo ago
Complementary trick: set
optimizeDeps.excludefor your own workspace packages. You do not want esbuild pre-bundling your own source, you want Vite serving it so HMR still works. If a linked package accidentally ends up in the optimized bundle you lose hot reload for it and spend an hour confused about why saving a file does nothing.Reply
Report