新的ts编译工具
基本可以做到开箱即用, 从效率上看, 编译比tsc快, 比ts-node直接运行还快
但是无法进行类型检测, 这部分还是需要tsc执行
创建swc配置文件
.swcrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| {
"minify": true,
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": false,
"dynamicImport": true
},
"transform": {
"legacyDecorator": false,
"decoratorMetadata": true
},
"target": "esnext",
"keepClassNames": true,
"loose": false
},
"module": {
"type": "commonjs",
"strict": false,
"strictMode": true,
"lazy": false,
"noInterop": false
},
"sourceMaps": false
}
|
安装node依赖
1
| pnpm add -D @swc/cli @swc/core
|
编译整个文件夹
编译 单文件
1
| swc app.ts -o dist/app.js
|
如果需要把依赖一起打包的话, swc无法实现,还是需要rollup或者esbuild
esbuild 打包依赖命令如下
1
| esbuild index.ts --bundle --outfile=dist/bundle.js --platform=node --minify-whitespace --m inify-syntax --minify-identifiers
|