-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Prebundling of libraries with Svelte components #2612
Comments
This was the same in Sapper. Reloads were taking 60 seconds. I made a reduced version of the library including only the icons we required, and reloads started taking 20 seconds. Game changer. I suppose what this means is that, the library isn't properly tree-shakeable. |
I don't think there's anything we can change in the library or is related to tree shaking, but requires changes in Vite. I updated the description with more details |
Until vite can pre-bundle svelte libraries it's best to use deep imports to avoid paying the tax of loading all exported svelte components. Icon libraries are usually the worst in this context, luckily https://github.com/antfu/unplugin-icons does not suffer from this. |
I've seen some discussion in I've been meaning to try this approach myself for some libraries I've been working on but so far it hasn't been an issue enough to try. For icons I typically use |
Wow, that's a great solution! Yeah, I wonder if we could tweak that library and use it generally. I've asked the author in carbon-design-system/carbon-preprocess-svelte#20 |
@bluwy didn't we discuss something like that before? Main problem i see is that a generic preprocess-use-deep-import would have to resolve the intended target on the spot, following multiple reexports in the worst case |
I think we discussed something similar too about transforming the entrypoint with only the named imports, so it works more generically. The preprocessor technique is interesting though, I suppose it can be worked around by checking the Anywho, I've been working today on actually prebundling Svelte libraries. It seems to be working on this branch. Wish I thought about it sooner 😄 The caveats now are that:
In that branch, I have a big-component-library playground to test out. I'd appreciate if anyone likes to test this in their project as well. |
I don't think the prebundling delay is too much of a big deal since it's only the first time you start the dev server and doesn't happen on subsequent runs. Adding a link to the merged PR for the new feature for reference: sveltejs/vite-plugin-svelte#200 |
Since |
Vite 2.9 will add better support for prebundling Svelte libraries: vitejs/vite#6801 |
I haven't got any negative feedback so I hope all's good with |
Since
|
The main thing to do before graduating from experimental is probably sveltejs/vite-plugin-svelte#419 |
@bluwy Been using vitePlugin: { experimental: { useVitePreprocess: true }} for a fairly large web app & it has been great ! Except the annoying messages in the build, there has been no issues. It also handles the css background image url and a few other things better. And it allows you to remove Svelte preprocess from your package ! Thanks ! |
SvelteKit currently has prebundleSvelteLibraries forcefully enabled via inline config to vite-plugin-svelte. We are still working on enabling it by default in vite-plugin-svelte, which should happen in it's next feature release. See sveltejs/vite-plugin-svelte#494 After that SvelteKit can remove that setting from it's own code and users will be able to disable it completely if they so desire. |
Describe the bug
See illright/attractions#311 (comment) for the original report
It was loading all of
svelte-feather-icons
when you use just a few icons. Vite is supposed to do dependency pre-bundling to avoid this: https://vitejs.dev/guide/dep-pre-bundling.html#the-why. However, Vite's pre-bundling uses esbuild, so we disabled it on Svelte components because it doesn't know what to do with.svelte
files.Evan has proposed changing this. I'm finally a convert to the idea.
Reproduction
Try to use
svelte-feather-icons
Logs
System Info
Severity
serious, but I can work around it
Additional Information
You can work around it by doing deep imports
The text was updated successfully, but these errors were encountered: