Skip to main content
swc is a fast JavaScript/TypeScript transpiler written in Rust. It has built-in support for core-js and can inject polyfills based on your browser targets, similar to Babel’s @babel/preset-env.

How it works

swc’s env configuration block controls core-js integration. You specify:
  • targets — a browserslist query describing the environments you need to support.
  • mode — how polyfills are injected (entry or usage).
  • coreJs — the exact version of core-js you have installed.
swc uses compatibility data from core-js-compat to determine which modules each target environment requires.

Configuration

Add an env block to your .swcrc file:
.swcrc
{
  "env": {
    "targets": "> 0.25%, not dead",
    "mode": "entry",
    "coreJs": "3.49"
  }
}

Injection modes

In entry mode, swc replaces your top-level core-js import with the specific modules required for your target environments — the same behaviour as @babel/preset-env with useBuiltIns: 'entry'.Place a single import in your application entry point:
import 'core-js/actual';
swc rewrites it to import only the modules missing from your targets.
.swcrc
{
  "env": {
    "targets": "> 0.25%, not dead",
    "mode": "entry",
    "coreJs": "3.49"
  }
}

Choosing a core-js version

Set coreJs to the exact minor version installed in your project. swc uses this value to look up which modules were available at that version and avoid injecting modules that did not yet exist.
npm install --save [email protected]
.swcrc
{
  "env": {
    "targets": "last 2 Chrome versions, last 2 Firefox versions, IE 11",
    "mode": "entry",
    "coreJs": "3.49"
  }
}

Comparison with Babel

FeatureswcBabel (@babel/preset-env)
entry modeyesyes
usage modepartialyes (full)
Proposal supportvia core-js/proposals/*via proposals: true
Speedfaster (Rust)slower (JS)
Accuracygoodexcellent
For projects where polyfill accuracy matters most — particularly when targeting many environments or relying on proposal polyfills — Babel integration offers more complete coverage.

Build docs developers (and LLMs) love