swc Command: Fast JS/TS Compile in CI
swc is a Rust-based compiler that transpiles JS/TS far faster than Babel.
swc (@swc/cli) is a drop-in-ish, Rust-powered alternative to Babel for transpiling JavaScript and TypeScript. In CI it speeds up library builds and test transforms thanks to its native, multithreaded core.
Common flags
--out-dir DIR/-d DIR- compile a directory into DIR--out-file FILE/-o FILE- compile to a single output file--config-file PATH- path to a .swcrc config--source-maps/-s- emit source maps (inlinesupported)-C jsc.target=es2020- override config options on the command line--copy-files- copy files that are not compiled--strip-leading-paths- flatten output paths (newer CLI versions)
Example in CI
Transpile a TypeScript src tree to dist with maps using swc:
shell
swc src -d dist --source-maps --copy-files -C jsc.target=es2020Common errors in CI
- error: failed to read .swcrc - config missing or malformed JSON
- Syntax Error - file uses syntax not enabled in jsc.parser settings
- error: Bindings not found / platform binary missing - install the right @swc/core
- Caused by: failed to resolve config - wrong --config-file path
Key takeaways
- swc is a faster Babel substitute backed by a native Rust core.
- Override config inline with
-C key=valueinstead of editing .swcrc. - "Bindings not found" means the @swc/core native binary is wrong for the runner OS/arch.
Related guides
babel Command: Transpile JS in CIbabel transpiles modern JavaScript and JSX. Reference for --out-dir, --out-file, --config-file, --extensions,…
esbuild Command: Bundle & Compile in CIesbuild is a fast Go-based bundler/compiler. Reference for --bundle, --outfile, --minify, --platform, --targe…
tsc Command: Compile TypeScript in CItsc is the TypeScript compiler. Reference for --noEmit, --project, --watch, --build, --outDir, --strict, and…