-
Notifications
You must be signed in to change notification settings - Fork 143
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
Survey: How do you use Sucrase, what would make it better? #361
Comments
Here are my answers:
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
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 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.
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.
About 500,000 lines of code, about 10% of which has been converted to TypeScript.
For the dev server build, we use the webpack plugin. For tests, we use
Node 8, latest Chrome, latest Firefox.
Rough numbers:
Directly running Sucrase on the whole codebase takes about 5 seconds, compared with over a minute before.
There were a few nice advantages in addition to build performance:
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 |
@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 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 |
|
I think the best Sucrase could do is run 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 |
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. |
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 |
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 |
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. |
@sdegutis Sucrase is not support tree shaking?? beacause your example code doesn't use tree shaking |
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).The text was updated successfully, but these errors were encountered: