← 返回命令列表

Linux command

swc 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Compile file

swc [input.js] -o [output.js]

Compile directory

swc [src/] -d [dist/]

Watch mode

swc [src/] -d [dist/] -w

With source maps

swc [input.js] -o [output.js] --source-maps

Use config file

swc [input.js] -o [output.js] --config-file [.swcrc]

说明

swc (Speedy Web Compiler) is a JavaScript and TypeScript compiler written in Rust, designed as a significantly faster alternative to Babel. It handles transpilation, JSX transformation, TypeScript stripping, and minification in a single tool. The compiler supports modern JavaScript features, downlevel compilation to older targets, and React JSX transformation. TypeScript files are compiled by stripping types without performing type checking, making it much faster than tsc for builds where type checking is handled separately. SWC can process individual files, entire directories with watch mode for development, and generates source maps for debugging. It is used as the compilation engine by tools like Next.js and Parcel.

参数

-o _FILE_
Output file.
-d _DIR_
Output directory.
-w
Watch mode.
--source-maps
Generate source maps.
--config-file _FILE_
Configuration file.
--sync
Synchronous mode.

FAQ

What is the swc command used for?

swc (Speedy Web Compiler) is a JavaScript and TypeScript compiler written in Rust, designed as a significantly faster alternative to Babel. It handles transpilation, JSX transformation, TypeScript stripping, and minification in a single tool. The compiler supports modern JavaScript features, downlevel compilation to older targets, and React JSX transformation. TypeScript files are compiled by stripping types without performing type checking, making it much faster than tsc for builds where type checking is handled separately. SWC can process individual files, entire directories with watch mode for development, and generates source maps for debugging. It is used as the compilation engine by tools like Next.js and Parcel.

How do I run a basic swc example?

Run `swc [input.js] -o [output.js]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o _FILE_ do in swc?

Output file.