项目目录外部的tsconfig.json文件 [英] tsconfig.json file outside of project directory

查看:171
本文介绍了项目目录外部的tsconfig.json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目 portal .在开发过程中,我意识到我实际上需要在存储库中进行多个项目.因此,我现在有一个像这样的项目结构:

I have a project portal. As I developed, I realised I need multiple projects within the repository essentially. Therefore, I now have a project structure like so:

我想知道,是否可能在 portal shop 目录之外都包含 tsconfig.json 文件,这意味着打字稿编译器选项将适用于两个项目?在门户项目上执行 npm run serve 时,我似乎收到此错误:

I was wondering, would it be possible to have tsconfig.json file outside of both portal and shop directories meaning the typescript compiler options would apply across both projects? I seem to be getting this error when I do npm run serve on the portal project:

Error: Cannot find "C:\Git\ui\portal\tsconfig.json" file. Please check webpack and ForkTsCheckerWebpackPlugin configuration. 
Possible errors: 
  - wrong `context` directory in webpack configuration (if `tsconfig` is not set or is a relative path in fork plugin configuration)
  - wrong `tsconfig` path in fork plugin configuration (should be a relative or absolute path)

我不太确定它的来源,因为在我的代码库中没有定义这样的文件路径.

I'm not too sure where its coming from because no where in my codebase has such filepath defined.

tsconfig.json 的内容为:

{
 "compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": "portal",
"types": [
  "webpack-env"
],
"paths": {
  "@/*": [
    "src/*"
  ]
},
"lib": [
  "esnext",
  "dom",
  "dom.iterable",
  "scripthost"
]
 },
 "include": [
  "portal/src/**/*.ts",
  "portal/src/**/*.tsx",
   "portal/src/**/*.vue"
 ],
 "exclude": [
 "node_modules"
 ]
}

推荐答案

尝试以下操作:保留现有的 tsconfig.json ,然后在每个文件夹中创建一个 tsconfig.json ,其中包含以下内容:

Try this: keep your existing tsconfig.json, then in each of the folders create a tsconfig.json with the following content:

{
    "extends": "../tsconfig.json"
}

这篇关于项目目录外部的tsconfig.json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆