Speed up TypeScript compilation in development so file changes reflect almost instantly without waiting for the full compiler
Run TypeScript files directly in Node.js by registering Sucrase as a loader with no separate build step
Compile JSX and TypeScript during development while running the TypeScript compiler separately for type checking only
Sucrase is a JavaScript compiler that converts TypeScript, JSX, and Flow code into plain JavaScript that browsers and Node.js can run. It serves the same basic purpose as Babel, but with a much narrower scope: rather than trying to support every JavaScript feature and old browser version, Sucrase assumes you are running modern software and focuses only on the non-standard syntax extensions that modern runtimes still cannot understand on their own. The payoff for that narrower scope is speed. According to benchmarks in the README, Sucrase compiles code roughly 20 times faster than Babel. When processing the Jest codebase (about 360,000 lines), Sucrase finished in 0.57 seconds, while Babel took 9.18 seconds. This makes Sucrase practical as a development-time tool where you are recompiling frequently. Sucrase handles a specific set of transforms. The TypeScript transform strips type annotations and removes TypeScript-only syntax so the code can run in JavaScript, but it does not check whether your types are correct. That job is left to the TypeScript compiler run separately. The JSX transform converts JSX syntax (the HTML-like syntax used in React code) into standard JavaScript function calls. The Flow transform strips Flow type annotations. There is also a transform that converts ES module import/export statements to the older CommonJS format that older Node.js projects expect. Using Sucrase in a Node.js project is straightforward: install it and pass a register flag when starting your program, and Node.js will use Sucrase to compile TypeScript files on the fly. It also integrates with ts-node, a popular tool for running TypeScript in Node. The parser in Sucrase is adapted from Babel's parser, and the README notes the project would not exist without Babel's prior work.
← alangpierce on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.