Skip to content
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

Merged
merged 1 commit into from
Jun 20, 2021
Merged

Add faq docs about limitation in vite-plugin-svelte #1665

merged 1 commit into from
Jun 20, 2021

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Jun 10, 2021

Add paragraph under FAQ package section about @sveltejs/vite-plugin-svelte's docs regarding the optimizeDeps.exclude trick.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts

@Conduitry
Copy link
Member

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.

@bluwy
Copy link
Member Author

bluwy commented Jun 10, 2021

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.

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).
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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

@benmccann benmccann added the documentation Improvements or additions to documentation label Jun 14, 2021
@bluwy
Copy link
Member Author

bluwy commented Jun 19, 2021

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!

@benmccann
Copy link
Member

@bluwy it looks like this PR will need to be rebased

@changeset-bot
Copy link

changeset-bot bot commented Jun 20, 2021

⚠️ No Changeset found

Latest commit: 108d877

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@bluwy
Copy link
Member Author

bluwy commented Jun 20, 2021

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.

@benmccann benmccann merged commit 2fb0386 into sveltejs:master Jun 20, 2021
@bluwy bluwy deleted the patch-1 branch June 22, 2021 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants