Configs2026年5月30日·1 分钟阅读

Sucrase — Super-Fast Alternative to Babel for Modern Runtimes

A lightweight JavaScript and TypeScript compiler that focuses on speed by only supporting transforms needed for modern runtimes, achieving 20x faster compilation than Babel.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Sucrase
直接安装命令
npx -y tokrepo@latest install 557720ac-5c65-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Sucrase is a JavaScript and TypeScript compiler built for speed. Unlike Babel, which supports every possible syntax transform, Sucrase focuses exclusively on transforms needed for modern environments — TypeScript, JSX, and module syntax — and does them extremely fast.

What Sucrase Does

  • Compiles TypeScript to JavaScript by stripping type annotations
  • Transforms JSX syntax into React.createElement or JSX runtime calls
  • Converts ES module import/export to CommonJS require/module.exports
  • Processes Flow type annotations by removing them from source
  • Operates as a CLI tool, Node.js register hook, or programmatic API

Architecture Overview

Sucrase works as a single-pass compiler. It tokenizes the source, identifies transform boundaries (type annotations, JSX tags, import statements), and generates output by copying source text and only modifying the relevant spans. This approach avoids building a full AST, which is why it is dramatically faster than Babel. The tradeoff is that it does not support every Babel plugin — only the most common transforms.

Self-Hosting & Configuration

  • Install via npm: npm install --save-dev sucrase
  • Run from the CLI: sucrase ./src -d ./dist --transforms typescript,jsx
  • Use as a Node.js register hook: node -r sucrase/register script.ts
  • Integrate with bundlers via @rollup/plugin-sucrase or esbuild (which uses a similar approach)
  • Available transforms: typescript, jsx, imports, flow, react-hot-loader

Key Features

  • Up to 20x faster than Babel for supported transforms
  • Single-pass architecture with no full AST construction
  • Supports TypeScript, JSX, ES modules, and Flow out of the box
  • Node.js register hook for running TypeScript files directly
  • Drop-in Babel replacement for projects that only need common transforms

Comparison with Similar Tools

  • Babel — full-featured compiler with plugin ecosystem; Sucrase is faster but supports fewer transforms
  • SWC — Rust-based compiler with broader transform support; Sucrase is pure JS and simpler to debug
  • esbuild — Go-based bundler and compiler; faster than Sucrase but primarily a bundler
  • tsc — official TypeScript compiler with type-checking; Sucrase only strips types without checking
  • tsx — Node.js loader for TypeScript; uses esbuild under the hood rather than Sucrase

FAQ

Q: Can Sucrase replace Babel in my project? A: If you only need TypeScript, JSX, and module transforms, yes. If you rely on advanced Babel plugins, no.

Q: Does Sucrase type-check TypeScript? A: No. It strips types without checking them. Run tsc separately for type-checking.

Q: How does the speed compare? A: Sucrase is typically 4-20x faster than Babel depending on the transform set and file size.

Q: Is it production-ready? A: Yes. It is used in production by tools like Vitest, Bun, and various build pipelines.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产