SWC (Speedy Web Compiler) là Rust-based JS/TS compiler — nhanh hơn Babel 20-70x single-thread, 70x với multi-core parallelization.
- Next.js adoption: từ Next.js 12, SWC thay thế Babel cho transpilation và Terser cho minification — cold build 5x nhanh hơn, HMR 3x nhanh hơn; tự động detect và migrate từ Babel config khi có .babelrc.
- Compatibility: SWC hỗ trợ hầu hết Babel transforms — preset-env equivalents, TypeScript, JSX, decorators.
- Plugin system limitations: SWC plugins viết bằng WebAssembly (WASM) — khó implement hơn Babel plugins (JS), ecosystem nhỏ hơn nhiều; một số advanced Babel transforms (custom macros, babel-plugin-macros) chưa có SWC equivalent. @swc/core dùng trực tiếp trong Node.js scripts, swc-loader cho Webpack, @vitejs/plugin-react có thể dùng SWC.
- Khi không thể dùng SWC: project phụ thuộc vào Babel plugins đặc biệt (babel-plugin-styled-components transformation, babel-plugin-import for tree shaking), hoặc cần custom transforms.
- Deno sử dụng SWC internally cho TypeScript transpilation.
SWC (Speedy Web Compiler) is a Rust-based JS/TS compiler — 20-70x faster than Babel single-threaded, 70x faster with multi-core parallelization.
- Next.js adoption: starting from Next.js 12, SWC replaces Babel for transpilation and Terser for minification — cold builds are 5x faster, HMR is 3x faster; automatically detects and migrates from Babel config when a .babelrc is present.
- Compatibility: SWC supports most Babel transforms — preset-env equivalents, TypeScript, JSX, decorators.
- Plugin system limitations: SWC plugins are written in WebAssembly (WASM) — harder to implement than Babel plugins (JS), much smaller ecosystem; some advanced Babel transforms (custom macros, babel-plugin-macros) have no SWC equivalent yet. @swc/core can be used directly in Node.js scripts, swc-loader for Webpack, @vitejs/plugin-react can use SWC.
- When SWC cannot be used: the project depends on special Babel plugins (babel-plugin-styled-components transformation, babel-plugin-import for tree shaking), or custom transforms are required.
- Deno uses SWC internally for TypeScript transpilation.