feat: enable optimizer for server environments during dev
#1185When combined with @cloudflare/vite-plugin, most deps are prebundled before they are loaded by the workerd runtime during development. This means that the esbuild optimizer plugin should generate server code in these cases instead of always generating client code. https://github.com/sveltejs/vite-plugin-svelte/blob/3119a4b53f36835a5a8d28b19cfb7c47abb8bbbd/packages/vite-plugin-svelte/src/plugins/setup-optimizer.js#L199
This is important to enable SvelteKit to work with the Cloudflare Vite plugin in development, which currently receives client Svelte code when performing SSR.
The Svelte compiler generates client/server code depending on the Vite environment when optimizing dependencies.
EDIT: sapphi mentioned it's possible to set a different esbuild plugin during the configureEnvironment hook
If we waited for Rolldown to officially replace esbuild, we wouldn't need to bother with tweaking the esbuild plugin. But I think that might still be a long time from now.
We could also probably workaround this by ensuring SvelteKit doesn't get optimized during development.
I cannot use vite-plugin-svelte without it
No description provided
Update packages/vite-plugin-svelte/src/plugins/setup-optimizer.js
• Jul 29, 2025, 8:34 AMCo-authored-by: Tee Ming chewteeming01@gmail.com
Co-authored-by: Tee Ming chewteeming01@gmail.com