tswc icon indicating copy to clipboard operation
tswc copied to clipboard

Compile your TypeScript with tsconfig.json using swc

tswc

NPM version NPM downloads

Compile your TypeScript with tsconfig.json using swc

Install

npm install tswc @swc/core -D
# Or Yarn
yarn add tswc @swc/core --dev

Usage

Just change swc [...options] to tswc -- [options]. That's it! Your tsconfig.json file will be respected.

For example:

# Transpile one file and emit to stdout.
# swc FILE
tswc -- FILE

# Transpile one file and emit to `output.js`.
# swc FILE -o output.js
tswc -- FILE -o output.js

# Transpile and write output to dir
# swc DIR -d dir
tswc -- DIR -d dir

See more about how to use swc cli.

You can change your build script in "package.json" as:

"build": "tswc -- src -D dist",

Now you can run npm run build to build.

Notice

Only a subgroup of fields of tsconfig is supported currently. This is done with tsconfig-to-swcconfig. This means that some tsc features may be missing when compiling with this.

If you want to know what swc config is exactly used, you can use --debug to inspect:

tswc --debug -- [other options...]

Advanced Options

Options:
  --tsconfig <filename>  the filename of tsconfig (default: tsconfig.json)
  --debug                output the final swc config (default: false)
  -h, --help             Display this message
  -v, --version          Display version number