swc
You are an expert in SWC, the Rust-based JavaScript/TypeScript compiler. You help developers replace Babel and Terser with SWC for 20-70x faster compilation, minification, and bundling — used by Next.js, Vite, Parcel, and Deno as their default compiler, handling TypeScript stripping, JSX transformation, polyfill injection, and code minification at native speed.
What this skill does
# SWC — Super-Fast Rust Compiler
You are an expert in SWC, the Rust-based JavaScript/TypeScript compiler. You help developers replace Babel and Terser with SWC for 20-70x faster compilation, minification, and bundling — used by Next.js, Vite, Parcel, and Deno as their default compiler, handling TypeScript stripping, JSX transformation, polyfill injection, and code minification at native speed.
## Core Capabilities
### Configuration
```json
// .swcrc
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true,
"dynamicImport": true
},
"transform": {
"react": {
"runtime": "automatic",
"importSource": "react"
},
"decoratorVersion": "2022-03"
},
"target": "es2020",
"minify": {
"compress": {
"dead_code": true,
"drop_console": true,
"passes": 2
},
"mangle": true
}
},
"module": {
"type": "es6",
"strict": true,
"lazy": false
},
"minify": true,
"sourceMaps": true
}
```
### CLI Usage
```bash
# Compile single file
npx swc src/index.ts -o dist/index.js
# Compile directory
npx swc src -d dist --source-maps
# Watch mode
npx swc src -d dist -w
# Minify
npx swc-minify input.js -o output.min.js
# Performance comparison (10K file project):
# Babel: 32s compile
# SWC: 0.5s compile (64x faster)
```
### Programmatic API
```typescript
import { transform, transformSync } from "@swc/core";
// Async transform
const output = await transform(sourceCode, {
filename: "app.tsx",
jsc: {
parser: { syntax: "typescript", tsx: true },
transform: { react: { runtime: "automatic" } },
target: "es2020",
},
module: { type: "es6" },
sourceMaps: true,
});
console.log(output.code);
console.log(output.map);
// Sync (for build tools)
const syncOutput = transformSync(sourceCode, {
jsc: { parser: { syntax: "typescript" }, target: "es2022" },
});
```
### Jest Integration
```javascript
// jest.config.js — Replace babel-jest with @swc/jest
module.exports = {
transform: {
"^.+\\.(t|j)sx?$": ["@swc/jest", {
jsc: {
parser: { syntax: "typescript", tsx: true },
transform: { react: { runtime: "automatic" } },
},
}],
},
};
// Test suite runs 3-5x faster than with babel-jest
```
## Installation
```bash
npm install -D @swc/core @swc/cli
npm install -D @swc/jest # For Jest
```
## Best Practices
1. **Replace Babel** — SWC handles TypeScript, JSX, decorators, polyfills; drop `.babelrc` entirely
2. **Next.js default** — Next.js uses SWC by default; no configuration needed
3. **Jest speedup** — Replace `babel-jest` with `@swc/jest`; test suites run 3-5x faster
4. **Minification** — Replace Terser with SWC minifier; same quality, 20x faster
5. **Target wisely** — Set `target: "es2020"` for modern browsers; `"es5"` only for legacy support
6. **Drop console** — Enable `drop_console` in minify config for production; removes console.log automatically
7. **Source maps** — Always enable `sourceMaps: true`; SWC generates source maps at negligible cost
8. **Plugin system** — Write SWC plugins in Rust (WASM); for custom AST transforms beyond configuration
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.