扩展 tsconfig.json 文件似乎没有扩展任何内容

Extending tsconfig.json file doesn't seem to extend anything

我有一个项目,我需要从中构建两种不同的产品。说我有

./src/advanced
./src/basic

所有代码都是用 Typescript 编写的,所以我需要用 tsc

编译它

因此,我创建了 3 个 tsconfig 文件

tsconfig-base.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "noImplicitAny": false,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "lib": ["es2018", "dom", "dom", "dom.iterable", "es6"],
    "importHelpers": true,
  },
  "exclude": ["node_modules", "**/*.spec.ts","dist"]

现在构建我拥有的 basic 产品

tsconfig-basic.json

{
  "extends": "./tsconfig-base.json",
  "compilerOptions": {
    "noEmitHelpers": true
  },
  "files": [
     "basic/main.ts"
  ]
}

而我编译如下

$> tsc -p ./tsconfig-basic.json

现在我有 2 个问题

1) 找不到文件 basic/main.ts,它在 ./basic/main.ts 中查找,而它应该在 ./src/basic/main.ts 中查找。为什么 baseUrl 没有放在前面?

2) 如果(1)是固定的,编译后的文件不会写入./dist。为什么这里不使用基本文件中的 "outDir": "./dist?当我将 outDir 添加到 tsconfig-basic.json 时,它按预期工作

无论如何,这里的扩展似乎不起作用,或者与我预期的不同。有什么关于如何改进我的设置的建议吗?

1) baseUrl 仅适用于像 webpack 这样的打包器。请参阅 TypeScript/10866

上的讨论


2) 不幸的是,这是设计使然。请参阅问题 TypeScript/29172

Quote Wesley Wigham (Microsoft Employee):
Path-based compiler options (outDir, outFile, rootDir, include, files) are resolved from the config file they're found in)

您需要为每个 tsconfig.json 文件重复 outDir

虽然有一个技巧。如果您从相关目录创建指向基本 Tsconfig 文件的符号链接并扩展符号链接版本而不是原始版本,所有路径都将根据您的期望进行解析。