Open alangpierce opened 5 years ago
Here are my answers:
Do you use Sucrase? If not, is there something stopping you from using it?
Yes, we use Sucrase at Benchling, on an engineering team of about 20. Originally, it was an opt-in flag both for JS tests and for the dev server, but recently we decided that it's stable and useful enough to be on by default, with a --no-sucrase
option to switch back to the old build in case things go wrong. The response has been really positive.
Which transforms do you use? What transpiler does Sucrase replace? (Babel, TypeScript compiler, or something else?)
Our code is a big React JSX codebase that is partially converted to TypeScript, so we use the jsx and typescript transforms, plus the imports transform when running tests (in node). We used to use enableLegacyBabel5ModuleInterop
and enableLegacyTypeScriptModuleInterop
, but I've since cleaned up our code to work with the latest CJS interop rules, so we don't need either of those anymore. We have some createReactClass
usages, so we make use of the display name transform.
In our normal build system without Sucrase, we use Babel 6 for .js files (we haven't upgraded to Babel 7 yet) and the TypeScript compiler for .ts and .tsx files.
Are you using Sucrase in production or just development?
Only development, and we have no plans to ever use it in production. We need to provide at least basic support for IE, so we'll use Babel and tsc for the forseeable future. I think the only reason we'd ever switch to using it in production is to keep production and development closer in sync. Production JS build performance certainly isn't a concern at all for us.
How big is your codebase?
About 500,000 lines of code, about 10% of which has been converted to TypeScript.
Which integrations do you use?
For the dev server build, we use the webpack plugin. For tests, we use sucrase/register
. We used to use the gulp plugin for ahead-of-time builds, but not anymore.
What runtime environments do you target for development? (Node version, Chrome version, etc)
Node 8, latest Chrome, latest Firefox.
How does development performance differ with and without Sucrase?
Rough numbers:
Directly running Sucrase on the whole codebase takes about 5 seconds, compared with over a minute before.
Have you seen any other advantages or disadvantages from using Sucrase?
There were a few nice advantages in addition to build performance:
undefined
at runtime.Are there any bugs, pain points, or missing features that you'd like to see fixed?
The main disadvantage is that React Hot Loader doesn't work at all. We were already having trouble with React Hot Loader reliability, so this didn't seem like a big loss, but we would like to get it figured out in the future if possible.
In the past, there were some bugs and missing syntax features, but things seem to have been stable for a while now.
Not a user, but was searching for faster Typescript transpilation solutions, so Sucrase looked very interesting - unfortunately, need React hot loader!
@alangpierce It would be nice if sucrase
has a possibility of type checking for typescript and flow. Without this features development
is not very useful in my opinion
@MaxGraey Interesting, could you describe your build setup more? From my experience, it's always best to decouple typecheck/lint from transpile/bundle, even though the easiest build setups tend to do both at the same time. In all of my TypeScript projects, I run typechecking in my editor (using an editor plugin), when running tests/lint (using tsc
), and in CI (also using tsc
). I intentionally don't make it so a type error anywhere in my project means I can't run my code at all. There's also https://github.com/Realytics/fork-ts-checker-webpack-plugin to have webpack run the typechecker, though I don't use that because I find in-editor typechecking to be enough.
cc @yang, if you haven't already separated transpile and typecheck, that's an easy way to speed up your TS build signficantly. In ts-loader, it's transpileOnly: true
, and other tools have similar settings. Sucrase improves further upon that by making transpile faster.
fork-ts-checker-webpack-plugin
require rollup or webpack, CI & tests require tsc
. They both eat up hard disk space. Ideally, it would be nice to have one lightweight tool that could completely replace typescript or flow.
tsc
ships with TypeScript, and there isn't really a reasonable way to do type checking without TypeScript installed. The transpile aspect of TypeScript is simple enough that a project like Sucrase can replace it, but the typecheck aspect of TypeScript is much, much more complicated. I guess it maybe could be possible to make a weaker-but-faster typechecker for TS code, but that would be a totally different project, way outside the scope of Sucrase.
I think the best Sucrase could do is run tsc
(maybe programmatically) alongside the transpile step, but that would make Sucrase dramatically slower, slow enough that it would be better to just use tsc
by itself for typecheck and transpile. Happy to accept suggestions on how Sucrase could make config easier, but I also want to avoid external dependencies, especially when there isn't any problem using other tools alongside Sucrase.
As one example, at my work, running a single test takes about 5 seconds, about 1 second of which is in Sucrase. Doing a full typecheck takes about 30 seconds, so forcing a typecheck at the start of any test would make it much, much harder to iterate on tests. Incremental typechecking in the TS language service (which runs in editor plugins) is faster, but that's harder to do from the CLI.
@alangpierce Yeah we already use transpileOnly, and we're only seeing up to 33% speedup from it in incremental rebuild speed (with typechecking, takes just under 10s). I'm seeking something much faster, hence the interest in your project!
I use @sucrase/jest-plugin
and love it. My only pain point is that Node 6 is not supported.
We use Sucrase to transform all our JSX file to JS files which are then later fed into Closure Compiler (for type checking and minification). This is both in dev and prod
We have ~1100 jsx files and most of our build tool chain is in python. Python just calls out to Node.js to do the transformation. However, since the startup time of Node.js (plus sucrase) is in the order of 200ms that is a lot of wasted time. This is why we use Nodegun. Giving us transformation times as low as 3ms and for large files around 50ms. Of course we could have refactored the build tools to hand in all the files once but that would require lots of work.
Performance is great! We started off using JSXTransformer running inside Nashorn (Java JVM) (~300ms per file). That one was discontinued and we switched to Babel (still inside Nashorn). Babel was super slow, maybe 500ms to a few seconds for large files. Also Nashorn is an ES3 environment so we had to compile Babel down to a single ES3 file (babel-standalone) which was annoying.
We might use Sucrase for ts in the future
es7 bind operator would make it better, the main annoyance in javascript is the lack of easy 'this' handling
@Meai1 Make sense! Unfortunately, the bind operator is currently a stage 0 proposal ( https://github.com/tc39/proposals/blob/master/stage-0-proposals.md , https://github.com/tc39/proposal-bind-operator ), so I think it's too early to implement in Sucrase. Sucrase can handle a few future JS features, especially the simple ones, but for very experimental proposed features, it's probably best to use Babel.
@yang FYI I just released Sucrase 3.9.0 with react-hot-loader support. Hopefully that unblocks your use case!
Hey! Really love the library. I'm working on a set of guides that use Sucrase, Gulp and Rollup for a minimal modern build tool configuration, stripping out babel/webpack. So far it has worked flawlessly.
It's currently being used in production for Urbit's Landscape app (http://github.com/urbit/landscape). I just use it for JSX transformation with the gulp plugin. ~5k lines total in the source code.
I'm a big fan of having a clean, simple build tool setup. Sucrase does the job perfectly. Our gulpfile is only 117 lines and understandable with basic JS experience. I don't think I'll go back to webpack.
Source map support is a must.
I'm using this with rollup especially for compiling typescript files.
TypeDefinition generation should be available or respectable in tsconfig.json
setting declaration: true
A watch/respawn feature for Typescript would be cool.
I'm trying to use it to remove Typescript from some source code in a project, making it a regular Javascript+JSX project. But it seems to not really work for that, since you need to use the "JSX" transform to not get a syntax error, but I actually want the JSX to come through in the other end :)
Trying to use it in a component library that is currently just running tsc -b
in a monorepo. Love the speed, but would really love to see sucrase output the declaration files d.ts
instead of just stripping them.
@alangpierce
Sucrase made the new TypeScript web framework Novo Cantico much faster than when it was using Babel or even esbuild.
The one thing that might make Sucrase better for this use-case is to save import names directly in the context.
Currently, if you have this:
import {foo} from 'bar';
console.log(foo);
It seems Sucrase translates this into:
const _bar = require('bar');
console.log(_bar.foo);
When using VS Code's debugger, and placing a breakpoint on the console.log line, hovering over foo
doesn't show anything, because it doesn't exist at runtime. That's the only thing I would add so far.
I use sucrase in production, and I feel developers using my library should use it too! I'm pretty much confident with using it, and if there's any missing feature, we could simply make an issue here 🙂. I target nodejs v18+, recent browser versions, deno & bun runtime too, and other serverless runtimes. I primarily use sucrase to convert {tsx, ts, jsx, js} to js.
What I'm hoping to see is sucrase (getting forked if possible, or a different package) have support for vuejs sfc components & svelte components getting transpiled. It would widen my web framework ecosystem to support vuejs and svelte alongside reactjs.
@sdegutis Sucrase is not support tree shaking?? beacause your example code doesn't use tree shaking
A watch/respawn feature for Typescript would be cool.
I'd like to echo this statement
For anyone watching this repo (or otherwise seeing this issue), it would be great to get information on how Sucrase is being used and how it could improve! Feedback of any form would be great, but here are some example questions that might provide a good template. Feel free to answer any/all that are relevant.
Some of my goals in asking these questions:
enableLegacyBabel5ModuleInterop
andenableLegacyTypeScriptModuleInterop
in a future breaking change, mostly just for simplicity. I also may want to drop support for Flow if it's rarely or never used, since I don't use it and it's non-trivial to maintain (though still quite a bit easier to implement than TypeScript).