所有项目/工作空间的通用 `tsconfig`

问题描述 投票:0回答:1

我正在将几个不相关的打字稿项目重新组织成单一存储库结构。目前我在每个工作区都有一个

tsconfig.json
文件,它们都是相同的。我希望在所有项目 tsconfigs 的基本文件夹而不是中有一个“通用”tsconfig。这是我的项目结构的示例:

packages/
| foo/
| | src/
| | | index.ts
| | package.json
| | tsconfig.json
| bar/
| | src/
| | | index.ts
| | package.json
| | tsconfig.json
| asd/
| | src/
| | | index.ts
| | package.json
| | tsconfig.json
package.json

./packages/foo/tsconfig.json
(例如):

{
  "compilerOptions": {
    "strict": true,
    "outDir": "dist",
    "declaration": true,
    "declarationDir": "types",
  },
  "include": [
    "src",
  ],
}

如果我按原样保留文件,并将其移动到

./
,那么它找不到任何输入,大概是因为它正在寻找不存在的
./src

我很想创建一个像这样的

./tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "outDir": "$PWD/dist",
    "declaration": true,
    "declarationDir": "$PWD/types",
  },
  "include": [
    "$PWD/src",
  ],
}

不幸的是,我收到此错误:

error TS18003: No inputs were found in config file '/<my_path>/tsconfig.json'. Specified 'include' paths were '["$PWD/src"]' and 'exclude' paths were '["$PWD/dist","$PWD/types"]'.

有没有办法让 tsconfig 中的路径自动扩展到我正在工作的任何目录,或者为我的所有项目使用单个 tsconfig 文件?

typescript tsconfig
1个回答
0
投票

您可以创建一个基础

tsconfig.json
并使用
tsconfig.{project}.json
extends
中扩展它。

要构建

{project}
,请运行
tsc --project tsconfig.{project}.json

即,

tsconfig.json

{
    "compilerOptions": {
        "strict": true,
        "outDir": "dist",
        "declaration": true,
        "declarationDir": "types",
    },
    "include": [
        "src",
    ],
}

tsconfig.json

{
    "extends": "tsconfig.json",
    "compilerOptions": {
        "destinationDir": "foo/dir"
    },
    "include": [
        "foo/src",
    ],
}

构建

foo
tsc --project tsconfig.foo.json

© www.soinside.com 2019 - 2024. All rights reserved.