Why SWC
Next.js uses SWC for several reasons:- Performance — ~3x faster Fast Refresh and ~5x faster production builds compared to Babel.
- Extensibility — SWC can be used as a crate inside Next.js without forking the library.
- WebAssembly support — Rust’s WASM target means Next.js can compile on any platform, including environments where native binaries are unavailable.
- Ecosystem — SWC is maintained by the Vercel team and used across the JavaScript ecosystem.
What the compiler handles
TypeScript and JSX
TypeScript and JSX
SWC strips TypeScript types and transforms JSX to
React.createElement calls (or the automatic JSX runtime). This is the baseline transform applied to every file in your application.Minification
Minification
Since Next.js 13, the SWC compiler minifies production output by default. This is 7x faster than Terser.
Starting with Next.js 15, minification cannot be customized via
next.config.js. The swcMinify flag has been removed.Dead code elimination
Dead code elimination
The compiler removes server-only code from client bundles and client-only code from server bundles using compile-time
if/else branches that evaluate process.env.NODE_ENV and other build-time constants.Source maps
Source maps
Source maps are generated for both client and server bundles, enabling accurate stack traces during development and in production error monitoring tools.
Supported transforms
Styled Components
Port ofbabel-plugin-styled-components. Adds server-side rendering support and display names for styled components.
Emotion
Port of@emotion/babel-plugin. Adds source maps and auto-labeling to Emotion CSS-in-JS.
Relay
Compiles Relay GraphQL queries at build time:Remove React properties
Removes JSX properties matching a regex. Commonly used to stripdata-test* attributes from production builds:
Remove console calls
Stripsconsole.* calls from application code (not node_modules):
Module transpilation
Transpiles and bundles dependencies from local packages (monorepos) ornode_modules:
Build-time variable replacement
Statically replaces variables at build time using thedefine option:
Build lifecycle hooks
Run custom code after production compilation finishes, before type checking and static generation:Experimental features
SWC plugins
SWC supports experimental plugins written in WebAssembly:swcPlugins is a tuple of the npm package name (or path to a .wasm binary) and a configuration object.
SWC trace profiling
Generate Chromium trace events to profile the compiler’s internal transforms:.next/swc-trace-profile-{timestamp}.json. Open them in Perfetto or chrome://tracing.
Babel fallback
If your project has a.babelrc file, Next.js automatically falls back to Babel for transforming individual files. This ensures compatibility with existing applications that use custom Babel plugins.
If you are using a custom Babel setup and want to migrate to the SWC compiler, remove .babelrc and replace any custom transforms with the SWC plugin API or one of the built-in transforms above.
Compilation with Babel active is ~17x slower than with SWC. Migrating to SWC is recommended for most applications.
Version history
| Version | Changes |
|---|---|
v15.0.0 | swcMinify flag removed; minification always uses SWC |
v13.1.0 | Module transpilation and modularize imports stable |
v13.0.0 | SWC minifier enabled by default |
v12.3.0 | SWC minifier stable |
v12.2.0 | SWC plugins experimental support added |
v12.1.0 | Styled Components, Jest, Relay, and other transforms added |
v12.0.0 | Next.js Compiler introduced |
