85 points · by andrewstuart · 4y ago · 53 comments
[0] https://datastation.multiprocess.io/blog/2021-11-13-benchmar...
But I am not a professional or anything like that, so very much YMMV!
Realistically they have fairly different goals:
- esbuild’s goal is to be a fast JS/JSX/TS compiler and bundler with a simple plugin system to extend its behavior. It’s expected to largely stop adding scope there.
- SWC’s goal is to be a fast JS/JSX/TS compiler, bundler, and extensible code transformer with broad compatibility with Babel and direct support for AST transformation. It’s also integrated into Deno, in a lower level way than APIs exposed by esbuild, so it’s a fair bit more general purpose (whether that’s intended or not, I don’t know).
[1]: https://nextjs.org/blog/next-12#faster-builds-and-fast-refre...
> When an application has a custom Babel configuration, Next.js will automatically opt-out of using SWC
if they don't show a warning like they did with webpack 5 then that needs to be improved.
Run something like this for low latency development. Edit, save, see results, repeat.
In parallel, run the TypeScript compiler to eventually display type errors, inform your IDE with what it needs to deliver great completion, etc.
That said, I can understand one would want to use TypeScript and this in parallel, I just caution those going down this road that it is very easy to find yourself not really using TypeScript, and the second your TS doesn't compile with the official TS compiler, you are going to have upset users - and they might even be yourself! I for example quite liked ESBuild until I found situations where it didn't work, and then all those "instant" compiles were forgotten because I had to dig through esoteric, outside-of-my-expertise error messages and issues. Quick, type-safe hot reloading should be the target of course, but giving up type safety for speed is really not a good tradeoff.
In other words, instead of `tsc` you run `tsc --noEmit && swc`
You still need to know about the actual types in the program, and you still need to run them through `tsc` first regardless of whether `swc` accepts them or not.
Type checking can be a lot slower than an AST transformation, especially for a gradually typed language like typescript with tons of inferred types.
For this reason most large typescript code based I’ve seen run their build and type checking steps separately. Personally my workflow is to get it working, do a refactor or 2, then check the type checker, linter and full test suite at the end of the implementation.
If you're looking for fast compile times with type checking, we've been using JS++ [0], which is written in C/C++.
Cool to learn about JS++ but unlike babel/typescript/esbuild/swc JS++ cannot read TypeScript, it's a completely new/different language.