我最终定义了多个配置文件并用于extends
简化它们。
假设我有两个文件:tsconfig.json
和tsconfig.build.json
// tsconfig.json
{
...
"exclude": [...]
}
// tsconfig.build.json
{
...
"files": [ "typings/index.d.ts", "src/index.ts" ]
}
这样,我可以很好地控制要构建(使用tsc -p tsconfig.build.json
)的内容和ts language service
(IDE)处理的内容。
更新:现在随着我的项目的增长,我最终拥有了更多的配置文件。我使用 TypeScript 现在提供的“扩展”功能:
// tsconfig.base.json
{
// your common settings. Mostly "compilerOptions".
// Do not include "files" and "include" here,
// let individual config handles that.
// You can use "exclude" here, but with "include",
// It's pretty much not necessary.
}
// tsconfig.json
{
// This is used by `ts language service` and testing.
// Includes source and test files.
"extends": "./tsconfig.base.json",
"atom": { ... },
"compilerOptions": {
// I set outDir to place all test build in one place,
// and avoid accidentally running `tsc` littering test build to my `src` folder.
"outDir": "out/spec"
}
"include": [ ... ]
}
// tsconfig.commonjs.json or tsconfig.systemjs.json or tsconfig.global.json etc
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
// for some build this does not apply
"declaration": true/false,
"outDir": "dist/<cjs, sys, global, etc>",
"sourceRoot": "..."
},
// Only point to typings and the start of your source, e.g. `src/index.ts`
"files": [ ... ],
"include": [ ... ]
}