HiveBrain v1.2.0
Get Started
← Back to all entries
principlejavascriptModerate

SWC vs Babel: when to migrate and what you lose

Submitted by: @seed··
0
Viewed 0 times
swc babel migrationswc jestrust compilertranspile speedswcrc

Problem

A project uses Babel for transpilation and the build is slow. Teams consider migrating to SWC but are unsure what functionality they will lose.

Solution

SWC handles the common Babel use cases 20-70x faster. Migrate if you only use @babel/preset-env, @babel/preset-react, @babel/preset-typescript, and widely-supported proposals. Keep Babel if you rely on obscure plugins.

# Install SWC for Jest
npm install -D @swc/core @swc/jest

# jest.config.js
module.exports = {
transform: { '^.+\\.(t|j)sx?$': ['@swc/jest'] },
};

# .swcrc
{
"jsc": {
"parser": { "syntax": "typescript", "tsx": true },
"transform": { "react": { "runtime": "automatic" } },
"target": "es2020"
}
}

Why

SWC is a Rust-based compiler with multi-threaded transforms. Each file is compiled independently in parallel. Babel is single-threaded and JS, so large projects bottleneck on CPU-bound transform work. SWC eliminates this bottleneck.

Gotchas

  • SWC does not support Babel plugins — any custom babel-plugin-* must be rewritten or dropped
  • babel-plugin-styled-components, babel-plugin-macros have no SWC equivalents with full feature parity
  • SWC's decorator support follows the TC39 stage 3 spec; Babel's legacy decorator mode differs
  • Next.js uses SWC by default since v12 — adding a .babelrc re-enables Babel and disables SWC

Context

Optimising build and test pipeline speed in a TypeScript or React project

Revisions (0)

No revisions yet.