-
-
Notifications
You must be signed in to change notification settings - Fork 115
Re-optimize Svelte libraries when compile options change #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We already restart the devserver on svelte config change here:
and server.restart has a flag to force reoptimization https://github.com/vitejs/vite/blob/main/packages/vite/src/node/server/index.ts#L265 So to implement this, we have to check if the project has svelte dependencies and add that information to the restart call. Re-optimize always has to be done in full, as there could be dependencies between optimized dependencies that need to be updated as well. const forcePrebundle = hasSvelteDeps();
server.restart(forcePrebundle); Question is how to get that information there. |
That link is outdated, so here's a permalink for reference: https://github.com/vitejs/vite/blob/27e28328235d2f5c6a44129a7635b697097ec50a/packages/vite/src/node/server/index.ts#L271 Ok, so the challenge is we call |
Always reoptimizing would also affect non-svelte libraries. At the very least we should only do it when prebundleSvelteLibraries is active |
Not sure if I miss something, but I think this is already implemented in the vite-plugin-svelte/packages/vite-plugin-svelte/src/index.ts Lines 91 to 94 in 74fd16d
It is sort-of a hack but it prevents unnecessary restarts. |
ah, thanks! closing this then |
Uh oh!
There was an error while loading. Please reload this page.
Describe the problem
Because the optimized Svelte libraries depend on some Svelte compile options, whenever the Svelte options change we want to trigger a re-optimize when using the
prebundleSvelteLibraries
option.Describe the proposed solution
This info is currently kept in a _svelte_metadata.json in the Vite cache dir. So whenever that file doesn’t exist or if we compare and it’s stale, we would re-optimize.
As part of this, we should check if this metadata json is correctly saved in the right place, and not accidentally purged by Vite 3's new prebundling flow, eg the .vite/deps_temp thing.
Alternatives considered
Ideally we may want Vite to expose an API to say “mark optimized deps as stale and re-optimize on next run”
Importance
nice to have
The text was updated successfully, but these errors were encountered: