-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add faq docs about limitation in vite-plugin-svelte #1665
Conversation
While we're here touching this, I think the paragraph about Vite could use some reworking. When that was written, Vite was a direct dependency of the user's app. It's now a prod dep of SvelteKit instead. (And, currently, is actually pinned to a specific version, so there's no straightforward way for users to upgrade it anyway.) I don't have anything specific in mind about what the Vite paragraph should say instead. |
I've updated the Vite part. Didn't include the explanation of Vite being a prop dependency though, not sure if including that would help with troubleshooting the issue. |
documentation/faq/70-packages.md
Outdated
Finally, Vite has had some issues that have been fixed, so we recommend upgrading to the latest version of Vite. If you are still encountering issues we recommend searching both [the Vite issue tracker](https://github.com/vitejs/vite/issues) and the issue tracker of the library in question. Sometimes issues can be worked around by fiddling with the [`optimizeDeps`](https://vitejs.dev/config/#dep-optimization-options) or [`ssr`](https://vitejs.dev/config/#ssr-options) config values. | ||
Some issues may also be specific to Vite, so we recommend searching both [the Vite issue tracker](https://github.com/vitejs/vite/issues) and the issue tracker of the library in question. Sometimes issues can be worked around by fiddling with the [`optimizeDeps`](https://vitejs.dev/config/#dep-optimization-options) or [`ssr`](https://vitejs.dev/config/#ssr-options) config values. | ||
|
||
Finally, do check out `@sveltejs/vite-plugin-svelte`'s docs on the [limitation of importing some Svelte libraries](https://github.com/sveltejs/vite-plugin-svelte/tree/main/packages/vite-plugin-svelte#importing-third-party-svelte-libraries). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We avoid bundling Svelte components automatically #1148. I wonder if we should also automatically avoid optimizing them as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a discussion in discord from @dominikg regarding auto excluding optimizations of Svelte libraries. Looks like the exact heuristics are already implemented in that PR (this code specifically), but only for ssr.noExternals
.
I think the specific logic could live in vite-plugin-svelte instead, though I'm not sure if @dominikg has plans for that, or to fix the underlying prebundling issue directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I've dug into the prebundling issue last week and wrote my findings here. It should explain the reason why optimizeDeps.exclude
work as it is for Svelte.
@dominikg had raised some concerns in discord regarding the auto-exclude feature being directly in vite-plugin-svelte. I'll let him explain further, but perhaps we could handle it in SvelteKit for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that's some great investigation. I have to be honest I'm not totally following everything you've written as my understanding of the Vite internals is minimal. @dominikg, @GrygrFlzr, and @Rich-Harris probably know more about it than I do. It would be nice to file an issue that we can link to here or on the vite-plugin-svelte
readme that explain the reason for this restriction and so that people can follow along in case it is resolved at some point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benmccann Sorry for the long follow-up 😅 I've finally opened an issue at vitejs/vite#3910. Will start linking the issue to kit or vite-plugin-svelte if it proves to be a hard problem to tackle in Vite side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sent a PR for that here: sveltejs/vite-plugin-svelte#69
Is it possible to merge this in soon? Hoping to get this tip out in the public. Let me know if there's any other changes needed! |
@bluwy it looks like this PR will need to be rebased |
|
Rebased. I also moved it to on top of the "Vite issue tracker" part as I think the issue tracker should be the last resort if vite-plugin-svelte's workaround doesn't work. |
Add paragraph under FAQ package section about
@sveltejs/vite-plugin-svelte
's docs regarding theoptimizeDeps.exclude
trick.Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts