🌐 Web Development

SWC

Speedy Web Compiler

A Rust-based JS/TS compiler. More than 20 times faster than Babel.

πŸ“– Detailed Explanation

SWC (Speedy Web Compiler) is an ultra-fast JavaScript/TypeScript compiler written in Rust. It provides the same functionality as Babel (transpiling, minification, bundling) while boasting performance 20 times faster on a single thread and more than 70 times faster on multiple cores.

SWC has been the default compiler since Next.js 12 and is also supported by major build tools such as Vite and Parcel. Thanks to Rust's low-level optimization and efficient memory management, it maintains fast build times even in large projects.

SWC's core features include ES6+ transpiling, TypeScript/JSX transformation, code minification, and a plugin system. SWC plugins, which replace Babel plugins, are written in Wasm to provide cross-platform compatibility.

Turbopack is a next-generation bundler based on SWC, aiming for update speeds 700 times faster than Webpack. It dramatically improves dev server startup time and HMR speed in large codebases.

πŸ’» Code Example

// .swcrc μ„€μ • 파일
{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true,
      "dynamicImport": true
    },
    "transform": {
      "react": {
        "runtime": "automatic",
        "importSource": "@emotion/react"
      },
      "legacyDecorator": true,
      "decoratorMetadata": true
    },
    "target": "es2020",
    "loose": false,
    "minify": {
      "compress": {
        "unused": true,
        "dead_code": true
      },
      "mangle": true
    }
  },
  "module": {
    "type": "es6",
    "strict": true
  },
  "minify": true,
  "sourceMaps": true
}

// next.config.js - SWC μ»€μŠ€ν…€ μ„€μ •
/** @type {import('next').NextConfig} */
const nextConfig = {
  compiler: {
    // Emotion 지원
    emotion: true,
    // Styled Components 지원
    styledComponents: true,
    // ν”„λ‘œλ•μ…˜μ—μ„œ React DevTools 제거
    reactRemoveProperties: process.env.NODE_ENV === 'production',
    // console.log 제거
    removeConsole: process.env.NODE_ENV === 'production'
      ? { exclude: ['error', 'warn'] }
      : false,
  },
  experimental: {
    // Turbopack μ‚¬μš© (dev λͺ¨λ“œ)
    turbo: {
      rules: {
        '*.svg': {
          loaders: ['@svgr/webpack'],
          as: '*.js',
        },
      },
    },
  },
};

module.exports = nextConfig;

// λͺ…λ Ήμ€„μ—μ„œ SWC 직접 μ‚¬μš©
// npx swc src -d dist --source-maps --minify

πŸ—£οΈ Examples of Practical Conversations

In a technical meeting:

"Our CI build takes 8 minutes, but switching from Babel to SWC should finish it in under 2 minutes. If you upgrade to Next.js 12, you'll automatically use SWC."

In a technical interview:

"Why is SWC faster than Babel?" - "Because it's written in Rust and runs as a native binary. There's no JavaScript runtime overhead, and it's optimized with Rust's zero-cost abstractions."

In a code review:

"What if this Babel plugin isn't supported in SWC?" - "If you can't do it in .swcrc, you can add a Babel loader through the webpack config in next.config.js. But most things can be replaced with SWC built-ins."

Take a mock interview on this topic β†’ WIA SOOM AI Interview Β· Start for free

⚠️ Cautions

πŸ”— Related Terms

Babel Bundler Vite Next.js esbuild

πŸ“š Learn More

πŸ“„ SWC Official Documentation - Getting Started πŸ“„ Next.js Official Documentation - SWC Compiler πŸ“„ Turbopack Official Documentation