Communitygithub.com

G1Joshi/Agent-Skills - SWC

고성능 Rust 기반 JavaScript/TypeScript 컴파일, .swcrc 설정, @swc/jest를 통한 Jest 테스트, 그리고 축소(minification)에 대한 전문 SWC 지원. Babel을 SWC로 대체하여 더 빠른 빌드, 테스트 실행 가속화, 최신 ECMAScript 기능 컴파일 시 사용하세요.

Agent-Skills - SWC란 무엇인가요?

이 스킬은 SWC(Speedy Web Compiler)에 대한 포괄적인 지원을 제공합니다. SWC는 Rust로 작성된 초고속 JavaScript/TypeScript 트랜스파일러로, Babel보다 최대 20배 빠른 성능을 자랑합니다. Next.js, Deno와 같은 현대적인 번들러와 파이프라인에서 사용되며, React JSX, TypeScript, 최신 ECMAScript 기능을 효율적으로 컴파일합니다. 또한, `@swc/core`의 Node.js API를 통한 프로그래매틱 AST 조작, `@swc/jest`를 이용한 Jest 테스트 속도 향상, 그리고 프로덕션 자산의 빠른 축소(minification) 기능을 제공합니다. 이 스킬은 `.swcrc` 설정 파일 구성 방법, CLI를 통한 트랜스파일, `@swc/core` API를 사용한 코드 변환, 그리고 `@swc/jest`를 활용한 Jest 설정 등 실용적인 예제를 포함하고 있습니다. 특히, SWC는 타입 검사(type checking)를 수행하지 않으므로 CI/CD 파이프라인에서 `tsc --noEmit`과 함께 사용하는 것이 권장되며, ES2022 이상의 최신 타겟을 설정하여 네이티브 브라우저 기능을 활용하는 것이 좋습니다. 이 스킬은 SWC를 통해 빌드 성능을 극대화하고자 하는 개발자에게 유용한 가이드 역할을 합니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/G1Joshi/Agent-Skills/tree/HEAD/skills/tools/swc

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

SWC

SWC(Speedy Web Compiler)는 Rust 기반의 확장 가능한 플랫폼입니다. Next.js와 Deno 내부에서 사용되는 컴파일러입니다.

사용 시점

  • 고성능 JavaScript/TypeScript 트랜스파일: Babel을 Rust 기반 컴파일러로 교체하여 최대 20배 빠른 속도를 제공합니다.
  • Next.js 및 최신 번들러 파이프라인: React JSX, TSX, 최신 ECMAScript 기능 및 Webpack/Turbopack 자산을 트랜스파일합니다.
  • 프로그래매틱 AST 조작 및 코드 생성: @swc/core Node.js API를 사용하여 빠른 맞춤형 빌드 도구를 구축합니다.
  • 프로덕션 자산 축소(Minification): @swc/core 미니파이어를 사용하여 JS 및 CSS 번들을 극도로 빠른 속도로 축소합니다.

빠른 시작

1. 최소 .swcrc

{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true
    },
    "transform": {
      "react": {
        "runtime": "automatic"
      }
    },
    "target": "es2022"
  },
  "minify": false
}

2. CLI를 통한 컴파일

npx @swc/cli src -d dist

핵심 개념

프로덕션 SWC 설정 (.swcrc)

최신 TypeScript, React 19 JSX 런타임 및 모듈 트랜스파일 설정:

{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true,
      "dynamicImport": true
    },
    "transform": {
      "react": {
        "runtime": "automatic",
        "refresh": true
      }
    },
    "target": "es2022",
    "loose": false,
    "externalHelpers": true,
    "keepClassNames": true,
    "minify": {
      "compress": {
        "unused": true,
        "drop_console": true
      },
      "mangle": true
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": true,
  "sourceMaps": true
}

@swc/core API를 사용한 프로그래매틱 컴파일

Node.js 스크립트에서 소스 파일을 비동기적으로 트랜스파일:

import swc from "@swc/core";
import fs from "node:fs/promises";

async function compileTypeScript(filePath) {
  const code = await fs.readFile(filePath, "utf-8");

  const output = await swc.transform(code, {
    filename: filePath,
    sourceMaps: true,
    jsc: {
      parser: { syntax: "typescript", tsx: true },
      target: "es2022",
    },
    module: { type: "commonjs" },
  });

  console.log("Transpiled Code:\n", output.code);
  if (output.map) {
    console.log("Source Map Generated");
  }
}

compileTypeScript("./src/index.ts");

고속 CLI 트랜스파일

SWC 명령줄을 사용하여 디렉터리 트리를 직접 컴파일:

# 소스 맵과 함께 src/에서 dist/로 트랜스파일
npx swc src -d dist --copy-files --source-maps

# swcpack을 사용하여 트랜스파일 및 번들링
npx swc src/index.ts -o dist/bundle.js --minify

일반적인 패턴

@swc/jest로 Jest 테스트 가속화

문제: ts-jest를 사용한 TypeScript 트랜스파일로 인해 테스트 스위트 실행 속도가 매우 느립니다.
해결책: ts-jest를 @swc/jest로 교체합니다.

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

SWC 번들링 및 축소(Minification) 파이프라인

문제: 프로덕션 빌드 스크립트에 빠른 축소(Minification)가 필요합니다.
해결책: .swcrc 내에서 minify 옵션을 활성화합니다.

{
  "minify": true,
  "jsc": {
    "minify": {
      "compress": {
        "drop_console": true
      },
      "mangle": true
    }
  }
}

모범 사례 (2026)

  • 해야 할 것: @swc/helpers를 설치하고 externalHelpers: true를 활성화하여 트랜스파일러 런타임 헬퍼 스텁 복제를 방지합니다.
  • 해야 할 것: SWC는 타입 검사를 수행하지 않으므로 CI/CD 파이프라인에서 SWC와 함께 tsc --noEmit을 사용합니다.
  • 해야 할 것: 네이티브 최신 브라우저 기능을 활용하기 위해 target: "es2022" 이상으로 설정합니다.
  • 해야 할 것: @swc/jest 또는 @swc/register를 사용하여 단위 테스트 실행을 획기적으로 가속화합니다.
  • 하지 말아야 할 것: 꼭 필요하지 않은 한 Babel 플러그인에 의존하지 마십시오. 네이티브 SWC 플러그인(Wasm 플러그인)이 있는지 확인하십시오.
  • 하지 말아야 할 것: .swc 빌드 캐시 디렉터리를 Git 저장소에 커밋하지 마십시오.
  • 하지 말아야 할 것: 프로덕션 문제 해결을 위해 소스 맵을 생성하지 않고 SWC 축소(Minification)를 실행하지 마십시오.

문제 해결

오류 / 증상원인해결책
failed to handle: error parsing typescript.swcrc에서 플래그를 활성화하지 않고 TypeScript 구문(예: JSX 또는 데코레이터) 사용jsc.parser에 "syntax": "typescript", "tsx": true, "decorators": true가 있는지 확인합니다.
데코레이터 메타데이터가 출력되지 않음 (Reflect.getMetadata가 undefined 반환)transform.legacyDecorator 및 transform.decoratorMetadata가 설정되지 않음jsc.transform 내에 "legacyDecorator": true 및 "decoratorMetadata": true를 설정합니다.
Cannot find module '@swc/core-darwin-arm64'npm/yarn 설치 중 네이티브 바이너리 설치 실패npm install --force @swc/core를 실행하여 대상 아키텍처에 대한 네이티브 바이너리 가져오기를 트리거합니다.

참고 자료

Individual skills in this repo

This repo contains 11 individual skills — each has its own dedicated page.

G1Joshi/Agent-Skills

Expert Dask distributed computing assistance covering Dask DataFrames, Arrays, Futures, and cluster scaling. Use when analyzing datasets too large for pandas on a single machine or multi-node cluster.

G1Joshi/Agent-Skills

Expert dbt (data build tool) assistance covering SQL modeling, Jinja macros, tests, documentation, and semantic layer. Use when building analytics engineering pipelines on BigQuery, Snowflake, or PostgreSQL.

G1Joshi/Agent-Skills

Expert JAX assistance covering Autograd, XLA compilation (`jit`), vectorization (`vmap`), and parallelization (`pmap`). Use when building high-performance numerical computing and cutting-edge deep learning research.

G1Joshi/Agent-Skills

Expert Ray distributed computing assistance covering Ray Core (actors, tasks), Ray Train, Ray Tune, and Ray Serve. Use when scaling Python compute and ML training across multi-node clusters.

G1Joshi/Agent-Skills

Expert Git version control assistance covering branching, interactive rebase, cherry-pick, submodules, worktrees, and conflict resolution. Use when managing source code history and collaboration workflows.

G1Joshi/Agent-Skills

Expert K9s CLI assistance covering terminal Kubernetes cluster navigation, real-time log streaming, port forwarding, and pod debugging. Use when managing and troubleshooting Kubernetes clusters with speed.

G1Joshi/Agent-Skills

Expert Tig assistance covering text-mode interface for Git, interactive staging, commit graph visualization, diff exploration, and blame navigation. Use when navigating Git commit history in the terminal, staging hunks interactively, browsing file changes, or reviewing revisions.

G1Joshi/Agent-Skills

Expert Vim assistance covering modal editing, .vimrc configuration, registers, macros, search/replace, and plugin management via vim-plug. Use when editing text efficiently in terminal environments, writing Vimscript, recording macros, or configuring core Vim settings.

G1Joshi/Agent-Skills

Expert Zed editor assistance covering high-performance Rust-based text editing, multi-buffer editing, language server protocols (LSP), and AI assistant integrations. Use when configuring Zed settings.json, setting up language extensions, collaborating in real-time channels, or optimizing editor startup speed.

G1Joshi/Agent-Skills

Expert Zsh assistance covering shell customization, Oh My Zsh plugins, Zinit plugin manager, prompt engineering (Starship/Powerlevel10k), and shell scripting. Use when configuring .zshrc, writing Zsh automation scripts, optimizing shell startup time, or configuring tab-completion.

G1Joshi/Agent-Skills

Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].

관련 스킬