-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
Why not use tsc instead of esbuild for production build? #1585
Comments
The main reason is code output consistency between dev and prod. Using different TS transforms during dev and prod opens up room for all kinds of subtle issues. |
@yyx990803 I thought about this and would like to share two thoughts with you: (1) Prod is vastly different from dev anyway, and much more so than TS codegen. I won't even list everything but to mention just a few:
Testing prod builds is a must anyway and quite frankly, I trust the official TS codegen more than Esbuild. So I guess what I'm saying is: yes, that opens up the door to subtle differences but given everything that's going on anyway in a production build, I would be OK opting-in to that. (2) A way to remove the inconsistency is simply to use TSC for dev as well (as an option). There are benefits here:
So let's broaden this issue a bit: would you consider making the TS compiler for both dev and build configurable between esbuild and tsc? |
Absolutely not. The perf difference is significant (20~30x). It is ok from a single-file perspective, but in a typical project you can have hundreds of modules. That could be several seconds slower initial page load. |
FYI you can totally disable esbuild and write a custom plugin that uses TSC to handle the transpilation. It's just not going to be the default. |
Interesting but I don't have the bandwidth for that at the moment. Single-file transform should be very easy (just invoke tsc api with |
Speaking of raw speed, it would be nice if the full build could typecheck your project (a slow operation) in parallel to actually building it. Using Speaking of typechecking in parallel, I think there's a value in typechecking even during dev, but in the background. (don't block anything, report errors later when you're done). Estrella, kind of an alternative to Vite, does that. |
Type checking is only more efficient when it's done as an external system outside of Vite, because Vite is an on demand transform system during dev, shoe-horning typecheck into it just isn't right in the first place. Nothing prevents you from using something like |
Curious here what's the recommended tools / plugins / workflow? I would assume most Vue devs use VS Code. |
The default Vite + Typescript template uses
vuedx-typecheck
before calling build to typecheck your whole project.The official doc says you can call
tsc --noEmit
to the same effect.Which is good and I want full type checking during my final build.
But it makes me wonder if it's still worth using esbuild to compile Typescript after that.
The main benefit of esbuild is its speed.
This is really great during development, but during build if you fully type-check your project, you've lost most of the speed as tsc had to parse and analyze your whole project. Is it really worth it to not just ask TS to do the last step of emitting code?
If esbuild had no drawback I wouldn't care much. But using esbuild does come with a few drawbacks.
const enum
properly (a PR is in the works for the non-namespaced case, hopefully that'll work out. Namespaced const enums will never work without type checking)..d.ts
type definition file if you build a library.Would it be interesting to make building with tsc an option?
The text was updated successfully, but these errors were encountered: