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

create-svelte: vite.optimizeDeps all production deps #771

Closed
wants to merge 1 commit into from

Conversation

GrygrFlzr
Copy link
Member

This should solve the majority of CJS imports. There might be side effects but we can deal with those as they come up.

Also added a comment to point to Vite config page.

@dummdidumm
Copy link
Member

dummdidumm commented Mar 30, 2021

In #759 Rich set those to an empty array. Not sure if this would clash/behave/what's the better solution

@Rich-Harris
Copy link
Member

#759 was about optimizeDeps.entries, not optimizeDeps.imports — the former is used to populate the latter (but incorrectly in our case, because HTML entry points aren't exposed to Vite).

This should solve the majority of CJS imports.

I'm not 100% sure I understand what effect this will have — I thought optimizeDeps.include was a dev mode thing that prevented Vite from needing to reload the page when dependencies are encountered. Or is it designed to convert CJS into ESM so that it can be bundled? Or both?

(Relatedly, I found myself wondering yesterday why the 'dependencies updated, reloading page' thing is necessary at all. Can't Vite just delay responding until esbuild has done its thing?)

@pixelmund
Copy link
Contributor

If the dependency is large (with many internal modules) or is CommonJS, then you should include it.

https://vitejs.dev/guide/dep-pre-bundling.html#customizing-the-behavior

@dominikg
Copy link
Member

There were issues in the past where optimizing dependencies that use svelte caused 2 different sveltes to coexist at runtime which causes errors. Dedupe was not working correctly in that case.

Currently vite-plugin-svelte excludes svelte itself from being optimized and it is recommended to exclude all dependencies that use svelte themselves. As these are typically added as a dependency this PR could introduce problematic behavior.

We could try to see if optimizing svelte itself works in vite-plugin-svelte now without causing duplicate svelte, then stop excluding it and leave it up to vites default optimization detection. Neither "optimize every dependency" or "exclude everything" are good defaults imho. The latter was chosen for vite-plugin-svelte to reduce runtime errors.

@GrygrFlzr
Copy link
Member Author

Going to close for now since the import issues people were having before have either disappeared or don't seem to be fixed by this. Not sure if a dependency updated.

@GrygrFlzr GrygrFlzr closed this Mar 30, 2021
@Conduitry Conduitry deleted the optimize-deps branch April 1, 2021 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants