-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
fix: do not preserve type imports (WIP) #20
Conversation
a4f85fa
to
4f10572
Compare
Thanks, this is a great PR. That option should not be set by default. |
This was my initial thoughts. Do you think we could enable this option only during the preprocessing? |
It is possible if you use a separate preprocessor like @lukeed s https://github.com/lukeed/svelte-preprocess-esbuild the idea behind If you have any ideas for this i'd be happy to hear about it. But until then i'm going to remove that option from defaults. This is the esbuild release that added the preserve option specifically for sveltes usecase |
added a testcase and enabled the extra esbuild option for useVitePreprocess: true only. Does that work for you @SomaticIT ? |
I tried on my projects and it seems to work well. Thanks |
heads up @SomaticIT , a change has landed on vite main branch that will be released with vite 2.5.0 which starts to read/use tsconfig.json and use it for esbuild. PR on vite: vitejs/vite#4279 you can try to use https://github.com/fwouts/rollup-plugin-friendly-type-imports or you'll have to switch to using |
Hello,
I'm trying this plugin on a real-world project and the first thing to say is, it works very well, what a developer experience!
I noticed something that when I enable this plugin on a vite project (even without any svelte files): it breaks a lot of TypeScript modules because it preserve type imports.
Here is a little reproductible scenario:
If you compile this app with vite without
@sveltejs/vite-plugin-svelte
, it works as expected, the result would be:If you enable
@sveltejs/vite-plugin-svelte
, this will break with one of the following Error:You can reproduce this error by installing the playground I embedded in this PR
After a first inspection, I noticed that this plugin enforce the
importsNotUsedAsValues
Typescript compiler option with valuepreserve
. This force TypeScript users to separatetype imports
fromvalue imports
using the strict syntax:import type
. It can be a real problem on large TypeScript codebases because it force the developer to import its modules twice.I'm not sure if there is a good reason about this but when I comment this line, it does not impact my project and it resolves this issue on all
.ts
files of my project (read below about.svelte
files).Important Note
I also noticed that the same issue occured on
.svelte
files using this plugin. This is not the case using the rollup plugin. So when I switch a project (with a lot of TypeScript) fromrollup-plugin-svelte
tovite-plugin-svelte
, the project breaks because of type imports.This fix does not resolve the issue inside
.svelte
files. I'm not sure if this plugin is responsible of this or if the issue comes fromsvelte-preprocess
.Any idea?
I will investigate on this and give you more feedbacks.
Thanks again