Transpile JSX, TypeScript and esnext features on the fly with swc.
It will respect your tsconfig.json
(and .swcrc
if provided).
npm i @swc/core swc-register -D
# Or Yarn
yarn add @swc/core swc-register --dev
# Or pnpm
pnpm add @swc/core swc-register -D
node -r swc-register file.ts
It will use every mappable options from your tsconfig.json
to make swc works.
You can also add an npm script:
"ts": "node -r swc-register"
Now just run npm run ts -- file.ts
or yarn ts file.ts
instead.
const { register } = require('swc-register/dist/node')
register({
// ...swc options
})
There are some other swc registers like:
- swc-project/register: this is a babel-register alternative
- @swc-node/register: a similar project but doesn't has a perfect tsconfig mapping
MIT