swc

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SWC

SWC

SWC (Speedy Web Compiler) is a Rust-based extensible platform. It is the compiler inside Next.js and Deno.
SWC(Speedy Web Compiler)是一个基于Rust的可扩展平台,是Next.jsDeno内置的编译器。

When to Use

使用场景

  • Compilation: Replacing Babel.
  • Minification: Faster and often smaller than Terser.
  • Jest:
    @swc/jest
    speeds up tests by 10x.
  • 编译:替代Babel。
  • 代码压缩:比Terser更快,生成的文件通常更小。
  • Jest测试
    @swc/jest
    可将测试速度提升10倍。

Core Concepts

核心概念

Transforms

转换

Supports standard transforms (React JSX, TypeScript, legacy decorators).
支持标准转换(React JSX、TypeScript、旧版装饰器)。

Plugins (Wasm)

插件(Wasm)

SWC plugins are written in Rust (Wasm), making them fast but harder to write than Babel plugins.
SWC插件使用Rust(Wasm)编写,速度很快,但比Babel插件更难开发。

Best Practices (2025)

2025年最佳实践

Do:
  • Use
    swc-loader
    : In Webpack configs.
  • Use
    .swcrc
    : JSON configuration file (similar to
    .babelrc
    ).
Don't:
  • Don't stick with Babel: Unless you need a very niche Babel plugin that doesn't exist in SWC yet.
推荐做法
  • 使用
    swc-loader
    :在Webpack配置中使用。
  • 使用
    .swcrc
    :JSON配置文件(类似
    .babelrc
    )。
不推荐做法
  • 不要固守Babel:除非你需要某个SWC尚未支持的非常小众的Babel插件。

References

参考资料