简体   繁体   English

我可以将tsconfig文件放在一个项目中并在另一个项目中使用它吗?

[英]Can I put tsconfig file in one project and use it in another?

I have submodule in my solution projects. 我的解决方案项目中有子模块。 Both of them(1st 2nd projects) have .ts files, so I want to put tsconfig.json in submodule and share it for both of them. 他们两个(第一个第二个项目)都有.ts文件,所以我想把tsconfig.json放在子模块中并为它们共享它。

In file system they are located like this: 在文件系统中,它们的位置如下:

~/solution
--project1
  --Scripts
    --(ts files)
--submodule
  --tsconfig.json(I want to put it here)

~/solution
--project2
  --Scripts
    --(ts files)
--submodule

project1's name is equal with project2's name

I have tried to add rootDir to compilerOptions 我试图将rootDir添加到compilerOptions

   "rootDir": "..\\project1\\Scripts\\**\\*"

I tried to add 我试着补充一下

  "include": [
    "..\\project1\\Scripts\\**\\*"
  ]

None of them work for me. 它们都不适合我。

here is my tsconfig.json 这是我的tsconfig.json

{
  "compileOnSave": true,
  "buildOnSave": true,
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": true,
    "sourceMap": false,
    "target": "es5",
    "module": "none",
    "types": [],
    "emitBOM": false,
    "charset": "utf8"
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

If you want to share a tsconfig between two projects, you can extend a tsconfig.json file. 如果要在两个项目之间共享tsconfig,可以扩展tsconfig.json文件。 For example you have a shared file shared.json . 例如,您有一个共享文件shared.json Each project would have it's own tsconfig.json file and extending the base file shared.json , like so: 每个项目都有自己的tsconfig.json文件并扩展基本文件shared.json ,如下所示:

{
  "extends": "../shared",
  <options here that are different>
}

More info on this page: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html 关于此页的更多信息: https//www.typescriptlang.org/docs/handbook/tsconfig-json.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将项目引用与不同的 tsconfig 文件一起使用? - How can I use project reference with difference tsconfig files? 无法访问项目中的 tsconfig 路径 - Can not acces tsconfig paths in project 如何将 TypeScript tsconfig 放在另一个位置 - How to put TypeScript tsconfig in another location 如何获得 Typescript 脚本以使用 tsconfig 中定义的路径? - How can I get a Typescript script to use the paths defined in tsconfig? 如何生成 tsconfig.json 文件? - How can I generate a tsconfig.json file? 将 Angular 10 项目转换为 nativescript 共享项目时出现“无法解析 tsconfig.json 文件”错误 - “Can't parse tsconfig.json file” error when converting Angular 10 project to nativescript shared project 查找定义时,将另一个tsconfig.json文件添加到项目会混淆tsc - Adding another tsconfig.json file to project confuses tsc when finding definitions 是否可以将 tsconfig `paths` 与(项目)`reference` 一起使用? - Is it possible to use tsconfig `paths` with a (project) `reference`? 项目目录外的 tsconfig.json 文件 - tsconfig.json file outside of project directory Typescript / Eslint 在我开始的每个项目中都会抛出“无法读取文件 tsconfig.json” - Typescript / Eslint throws "Cannot read file tsconfig.json" in every project I start
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM