【问题标题】:how to use multiple tsconfig files (with conflicting compiler options)?如何使用多个 tsconfig 文件(编译器选项冲突)?
【发布时间】:2020-08-20 00:08:14
【问题描述】:

我的代码库包含两个打字稿项目:

  • 对于一个反应网络应用程序
  • 适用于网络工作者

网络工作者代码库是我的public/ 文件夹的一部分。这意味着在同一个工作区中有两个打字稿项目。如何使用 vs-code 完成这项工作?

到目前为止,我的问题基本上是重复的:How to use multiple tsconfig files in vs-code?

接受的答案解释了如何设置基本配置然后对其进行扩展:

//tsconfig.worker.json:

{
  "extends": "./tsconfig.json",
  "exclude": [
    "src/app"
  ]
}

但这在我的情况下不起作用。对于 worker.ts,我需要与 react 应用程序不同的 lib 配置。
可以在我的tsconfig.worker.json 中覆盖该配置并使用新设置进行编译。但是对于自动补全和错误高亮,vs-code只使用tsconfig.json,与webworker源码不兼容。

【问题讨论】:

    标签: typescript visual-studio-code web-worker tsconfig


    【解决方案1】:

    在与项目相同的目录中为每个项目提供自己的tsconfig.json,如下所示:

    └── src
        ├── tsconfig.json
        ├── shared
        │   ├── index.ts
        │   └── tsconfig.json
        ├── backend
        │   ├── index.ts
        │   └── tsconfig.json
        └── frontend
            ├── index.ts
            └── tsconfig.json 
    

    将所有常用设置放在根tsconfig.json 中,将项目特定设置放在它自己的tsconfig.json 中。请勿将它们命名为 tsconfig.json 以外的任何名称。

    每个项目的rootDir 设置将是./,这意味着它们将很好地独立/封装。您可以使用 Project Referencesas described in this answer 启用和管理它们之间的依赖关系。

    【讨论】:

      猜你喜欢
      • 2019-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-02
      • 2019-07-10
      相关资源
      最近更新 更多