swc src -d dist: Fast TypeScript Compile
swc src -d dist transpiles every file under src/ to JavaScript in dist/, far faster than Babel or tsc.
swc is a Rust-based transpiler used as a drop-in for Babel. It compiles, it does not type-check, so pair it with tsc as a gate.
What it does
The swc CLI (@swc/cli) transpiles a directory or file to plain JavaScript using the rules in .swcrc. It strips types and lowers syntax, but it does not perform type checking, so type errors pass through silently.
Common usage
swc src -d dist
swc src -d dist --strip-leading-paths
swc src -d dist --config-file .swcrc --source-maps trueOptions
| Flag | What it does |
|---|---|
| -d, --out-dir <dir> | Output directory |
| --config-file <f> | Path to the .swcrc config |
| --strip-leading-paths | Drop the src prefix from output paths |
| --source-maps <t> | true, inline, or false |
| -C <opt>=<val> | Override a config option inline |
| -w, --watch | Watch mode (not for CI) |
In CI
Because swc skips type checking, run tsc --noEmit as a separate step so type errors still fail the build. Use --strip-leading-paths (swc 1.4+) so output lands in dist/ rather than dist/src/, which breaks package "main" paths.
Common errors in CI
"Error: .swcrc: Syntax error" means invalid JSON in the config. "Cannot read properties of undefined" during transform usually means a jsc.parser mismatch (syntax: typescript vs ecmascript). Output ending up in dist/src instead of dist means you need --strip-leading-paths.