[英]Difference between tsconfig.json and tsconfig.app.json files in Angular
I'm a newbie in Angular.我是 Angular 的新手。 I used angular-cli
to learn about angular and I found the files tsconfig.json
and tsconfig.app.json
.我使用angular-cli
来了解 angular,我找到了文件tsconfig.json
和tsconfig.app.json
。 Both of these are typescript related and I found this link useful.这两个都是打字稿相关的,我发现这个链接很有用。
But why two such files has been used?但是为什么使用了两个这样的文件呢? Why can't the configurations in these two files be combined in one file?为什么不能将这两个文件中的配置合并到一个文件中? Please help me figure this out.请帮我解决这个问题。
there is nothing that prevents you from getting rid of the tsconfig.app.json
.没有什么可以阻止您摆脱tsconfig.app.json
。 it's just an additional config file that allows you to adjust your configuration on an app basis.它只是一个额外的配置文件,允许您根据应用程序调整配置。 this is eg useful when you have multiple apps in the same angular-cli
workspace.例如,当您在同一个angular-cli
工作区中有多个应用程序时,这很有用。
you could have the root folder with the tsconfig.json
and then a sub folder app-a
with a tsconfig.app.json
file and another app in the sub-folder app-b
with it's own tsconfig.app.json
, which contains a variation of the global configuration.你可以有与根文件夹tsconfig.json
,然后一个子文件夹app-a
具有tsconfig.app.json
文件和子文件夹中其他应用app-b
有它自己的tsconfig.app.json
,其中包含一个全局配置的变化。
the difference in configuration could eg be the output directory outDir
or the includes
or excludes
used.配置的差异可能是例如输出目录outDir
或使用的includes
或excludes
。
The difference is that tsconfig.app.json
is a file that is related to the Angular App in particular, while tsconfig.json
is a more general file that contains general typescript configuration.区别在于tsconfig.app.json
是一个特别与 Angular App 相关的文件,而tsconfig.json
是一个更通用的文件,包含通用的 typescript 配置。 It's especially useful when you have a micro frontends system, where there are multiple Angular subprojects, each of them with its own tsconfig.app.json
configuration.当您有一个微前端系统时,它特别有用,其中有多个 Angular 子项目,每个子项目都有自己的tsconfig.app.json
配置。 But if you want you could perfectly merge these two files into one, actually you surely noticed that tsconfig.app.json
contains the line:但是,如果您愿意,您可以完美地将这两个文件合二为一,实际上您肯定注意到tsconfig.app.json
包含以下行:
"extends": "./tsconfig.json"
which means that the whole App uses the configuration stated in tsconfig.app.json
plus the configuration in tsconfig.json
这意味着整个应用程序使用中所述的配置tsconfig.app.json
加在配置tsconfig.json
Just want to add one more point.只想补充一点。
It seems the tsconfig.app.json
(App specific one) will override the tsconfig.json
(global one).似乎tsconfig.app.json
(特定于应用程序的)将覆盖tsconfig.json
(全局的)。
My issue was with the types declaration from node not in scope of my Angular project and I was getting compile errors saying Buffer
is not found.我的问题是来自 node 的类型声明不在我的 Angular 项目范围内,我收到编译错误,说找不到Buffer
。
I first added the types declaration in tsconfig.json
thinking it will take effect in every app.我首先在tsconfig.json
添加了类型声明,认为它会在每个应用程序中生效。 But I had to add it to my app-specific tsconfig.app.json
file for it to take effect on my app.但是我必须将它添加到我的应用程序特定的tsconfig.app.json
文件中才能在我的应用程序上生效。
tsconfig.app.json is a configuration for the Angular application, tsconfig.app.json 是 Angular 应用程序的配置,
tsconfig.json is used for IDE integration tsconfig.json 用于 IDE 集成
tsconfig.json can be removed tsconfig.json 可以删除
According to https://github.com/angular/angular-cli/wiki/stories-rc.0-update#one-tsconfig-per-app根据https://github.com/angular/angular-cli/wiki/stories-rc.0-update#one-tsconfig-per-app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.