brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
swcYou 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 sp…
Independent GitHub snapshot · Automated classification · Original documentation governs
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.
// .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
}
# 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)
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.config.js — Replace babel-jest with @swc/jest
module.exports = {
transform: {
"^.+\\.(t|j)sx?quot;: ["@swc/jest", {
jsc: {
parser: { syntax: "typescript", tsx: true },
transform: { react: { runtime: "automatic" } },
},
}],
},
};
// Test suite runs 3-5x faster than with babel-jest
npm install -D @swc/core @swc/cli
npm install -D @swc/jest # For Jest
.babelrc entirelybabel-jest with @swc/jest; test suites run 3-5x fastertarget: "es2020" for modern browsers; "es5" only for legacy supportdrop_console in minify config for production; removes console.log automaticallysourceMaps: true; SWC generates source maps at negligible cost