5 ms·
Speedy Web Compiler – a fast TypeScript/JavaScript compiler
- lefrenchy 5y agoWith NextJS having a stake in this, i’m excited for the future of it! Awesome project.
- manigandham 5y agoCommonly called "swc" and often compared to esbuild: https://github.com/evanw/esbuild https://github.com/evanw/esbuild
- deleted 5y ago[deleted]
- newusertoday 5y agoanyone knows if there is equivalent of tsserver(used in language server protocol) in swc or esbuild?
- nawgz 5y agoI have found it a bit difficult to understand how TypeScript is involved here. Are they using the actual `tsc` library, or have they rolled their own? It is not very clear from the docs, overall I feel TypeScript support seems a bit of an afterthought reading thru the docs - they are very JS heavy in all examples
- replygirl 5y agothey rolled their own. if you're not emitting types it can be a lot faster than tsc
- Arnavion 5y agoThe parser supports parsing TS enough to be able to strip the TS-specific syntax. It doesn't run `tsc`, and it doesn't type-check or anything like that.
- styfle 5y agoTS type checking is on the roadmap https://github.com/swc-project/swc/issues/571 https://github.com/swc-project/swc/issues/571
- Arnavion 5y agoInteresting. I agree with the discussion thread that it would be a monumental task both to implement and then to keep up-to-date. I personally don't see the point, but I wish them luck.
- pjmlp 5y agoFor me that is equally to not supporting Typescript.
- kylecordes 5y agoThe general idea, I think: 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.
- pjmlp 5y agoThe Typescript compiler already generates the JS that we need, so nothing gained.
- nsonha 5y agoyou don't care about speed, we get it if things like swc does not exist then deno would have to use tsc, which is slower and contradict with being a replacement to nodejs, which is what tsc runs on
- pjmlp 5y agoThe judge is still out there if Deno will ever matter on the great scheme of things. But what do I know, I am a big fan of vanilajs, great framework.
- nsonha 5y agotsc is a compiler with type checking capability. This is merely a "transpiler" that transform TS to JS, an alternative to babel
- nawgz 5y agoYes, that I think is the source of my confusion - labelling oneself as a TypeScript compiler while actually not doing any type checking is slightly misleading, and the resultant builds being legal even while the TS is not is a strange paradigm to me, even if I recognize workarounds / other strategies exist
- charrondev 5y agoWell seeing how it is an alternative to babel (which also does not check types) it makes sense. 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.
- nawgz 5y ago> For this reason most large typescript code based I’ve seen run their build and type checking steps separately How big are we talking here? I have a mid-6-figures LOC codebase and the TypeScript compiler time is essentially negligible. I can't really understand how TSC is being compared to a full test suite in your world, the code is invalid if the types don't pass, so I'm more than happy to give it 1sec to tell me if I have a type mismatch
- nsonha 5y ago> compiler time is essentially negligible It is, but not neligible enough for hot reload. But people don't want to run tsc mostly because their IDEs already do and give them a better experience than constantly checking the terminal.
- slig 5y agoI'd rather not deal with dozens of babel-plugin-*. Can this or esbuild be used instead of babel?
- deleted 5y ago[deleted]
- leerob 5y agoYes. SWC is being used by Next.js to replace Babel. With SWC, compilation is about 17x faster than Babel in v12[1]. We created a CSS parser in Rust (through SWC), as well as ported many of the common Babel plugins to Rust[2]. Work is still ongoing here[3]. [1]: https://nextjs.org/blog/next-12#faster-builds-and-fast-refresh-with-rust-compiler https://nextjs.org/blog/next-12#faster-builds-and-fast-refre... [2]: https://nextjs.org/docs/advanced-features/compiler https://nextjs.org/docs/advanced-features/compiler [3]: https://github.com/vercel/next.js/discussions/30174 https://github.com/vercel/next.js/discussions/30174
- slig 5y agoFantastic, thank you very much!
- machiaweliczny 5y agoThose promises don't seem true in practice. I've tested next 11 vs 12 and got 0 speedup. Maybe because of M1 mac. IDK, would need to dig deeper - anyone had similar case?
- nsonha 5y agocheck the upgrading guide > 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.
- machiaweliczny 5y agoRemoved babel config. Maybe because I wasn't using babel much (just to transpile for more compatibility).
- eatonphil 5y agoIf you're curious about the difference between this and esbuild, TypeScript, and Babel, I wrote up a bit of background and did some independent benchmarks of TypeScript/React app build times [0]. SWC does well! [0] https://datastation.multiprocess.io/blog/2021-11-13-benchmarking-esbuild-swc-typescript-babel.html https://datastation.multiprocess.io/blog/2021-11-13-benchmar...
- beepbooptheory 5y agoEven if this was faster than esbuild by whatever milliseconds, I would still probably go with esbuild for the api. esbuild is a delightfully raw, scriptable thing, that is as simple or complicated as you want, you just make the node scripts and fun the functions. Config with swc looks to more closely resemble babel/webpack with extensive config objects, which is fine, but it can only mean that it loses out to esbuild for me. But I am not a professional or anything like that, so very much YMMV!
- k__ 5y agoI don't understand the difference between esbuild and swc.
- eyelidlessness 5y agoSWC is built in Rust, esbuild isn’t. /s 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).
- tazeg95 5y agoEsbuild can't yet convert to ES5. SWC can.
- robertwt7 5y agoWhy are people comparing this with esbuild? Isn’t esbuild a minifier and bundler, so it can replace webpack. As opposed to SWC replacing babel? Am i missing something?
- beepbooptheory 5y agoI think both esbuild and SWC remove the need to distinguish between a bundler and a transpiler. They both can do both. Esbuild only understands an AST that can "compile" to js, so it does what babel does just in that, can't speak to SWC but I bet it's the same situation.
- dizon 5y agoThis is misleading. It claims to support TypeScript but doesn't type check. If you're looking for fast compile times with type checking, we've been using JS++ [0], which is written in C/C++. [0] https://www.onux.com/jspp/ https://www.onux.com/jspp/
- jayflux 5y agoMany developers have type checking built into their IDE, so they usually know when something is wrong. Having it run again on every build (especially in watch mode) isn’t very efficient. Instead it’s faster to have type stripping as part of your developer workflow, then a full type check when you’re ready to commit.
- pjmlp 5y agoThe same IDEs generate the JS files when they are done with checking, so like why bother with a lesser solution.
- eatonphil 5y agoIt's not exactly misleading. Even TypeScript may be planning to support skipping type checking [0] so you can do faster compiles. Cool to learn about JS++ but unlike babel/typescript/esbuild/swc JS++ cannot read TypeScript, it's a completely new/different language. [0] https://github.com/microsoft/TypeScript/issues/29651 https://github.com/microsoft/TypeScript/issues/29651