问题描述
我的代码库包含两个打字稿项目:
My codebase contains two typescript projects:
- 用于 React Web 应用
- 对于网络工作者
Web Worker 代码库是我的 public/
文件夹的一部分.这意味着在同一个工作区中有两个打字稿项目.我怎样才能用 vs-code 做到这一点?
The web worker codebase is part of my public/
folder. Which means that there are two typescript projects in the same workspace. How can I make this work with vs-code ?
到目前为止,我的问题基本上是重复的:How在 vs-code 中使用多个 tsconfig 文件?
So far my question is basically a duplicate of: How to use multiple tsconfig files in vs-code?
接受的答案解释了如何设置基本配置然后扩展它:
The accepted answer explains how to set up a basic configuration and then extend it:
//tsconfig.worker.json:
{
"extends": "./tsconfig.json",
"exclude": [
"src/app"
]
}
但这在我的情况下不起作用.对于 worker.ts
,我需要一个与 react 应用程序不同的 lib
配置.
可以在我的 tsconfig.worker.json
中覆盖该配置并使用新设置进行编译.但是对于自动补全和错误高亮,vs-code 只使用了 tsconfig.json
,与 webworker 源代码不兼容.
But this doesn't work in my case. For the worker.ts
I need a different lib
configuration than for the react app.
It is possible to override that configuration in my tsconfig.worker.json
and to compile with the new settings. But for autocompletion and error highlighting, vs-code only uses the tsconfig.json
, which is not compatible with the webworker source code.
推荐答案
在与项目相同的目录中为每个项目提供自己的 tsconfig.json
,如下所示:
give each project its own tsconfig.json
in the same directory as the project, like so:
└── src
├── tsconfig.json
├── shared
│ ├── index.ts
│ └── tsconfig.json
├── backend
│ ├── index.ts
│ └── tsconfig.json
└── frontend
├── index.ts
└── tsconfig.json
将所有通用设置放在根目录 tsconfig.json
中,将项目特定的设置放在它自己的 tsconfig.json
中.不要将它们命名为 tsconfig.json
以外的任何名称.
Put all the common settings in the root tsconfig.json
, and the project specific ones in the its own tsconfig.json
. DO NOT name them anything other than tsconfig.json
.
每个项目的 rootDir
设置将是 ./
,这意味着它们将很好地独立/封装.您可以使用项目参考、如本答案中所述启用和管理它们之间的依赖关系.
The rootDir
setting for each project will be ./
, which means they will be nicely self-contained / encapsulated. You can enable and manage dependencies between them using Project References, as described in this answer.
这篇关于如何使用多个 tsconfig 文件(编译器选项冲突)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!