outDir 与 rootDir
outDir
是 js 代码输出目录,但是在输出时 tsc 会检测 ts 文件的最高目录,就像最大公约数一样。比如创建一个 ts 工程,仅有一个 index.ts 文件,目录结构如下:
tsconfig-test
├── package-lock.json
├── package.json
├── src
│ └── screen
│ └── membership
│ └── pages
│ └── index
│ └── index.ts
├── tsc_outputs
│ └── index.js
└── tsconfig.json
tsconfig.json:
{
"compilerOptions": {
"outDir": "tsc_outputs"
},
"include": ["src"]
}
则生成的 index.js 的目录是:
tsc_outputs/index.js
。
如果希望在tsc_outputs/screen/membership/pagees/index/
目录下,则需要设置rootDir
为./
:
{
"compilerOptions": {
"rootDir": "./",
"outDir": "tsc_outputs"
},
"include": ["src"]
}