【问题标题】:Difference between tsconfig.json and tsconfig.app.json files in AngularAngular 中 tsconfig.json 和 tsconfig.app.json 文件的区别
【发布时间】:2019-02-27 04:22:11
【问题描述】:

我是 Angular 的新手。我使用 angular-cli 来了解 angular,我找到了文件 tsconfig.jsontsconfig.app.json。这两个都与打字稿有关,我发现this link 很有用。

但是为什么使用了两个这样的文件呢?为什么不能将这两个文件中的配置合并到一个文件中呢?请帮我解决这个问题。

【问题讨论】:

    标签: html angular typescript angular-cli package.json


    【解决方案1】:

    没有什么可以阻止您摆脱tsconfig.app.json。它只是一个额外的配置文件,允许您基于应用程序调整配置。这是例如当您在同一个 angular-cli 工作区中有多个应用程序时很有用。

    您可以拥有带有tsconfig.json 的根文件夹,然后是带有tsconfig.app.json 文件的子文件夹app-a 和带有自己的tsconfig.app.json 的子文件夹app-b 中的另一个应用程序,其中包含一个变体全局配置。

    配置上的差异可以是例如是使用的输出目录outDirincludesexcludes

    【讨论】:

    • 一开始我只是排除了 tsconfig.app.json 文件,然后我得到了这个错误no such file or directory, stat '/home/ggg/Documents/SampleAngularApps/sample-ang-app/src/tsconfig.app.json'。所以我不得不包含这个文件。我使用 VSCode 作为编辑器。我不确定这是否是阻碍我的东西。
    • @kmg 你也需要在angular.json中修改,就这样
    • tsconfig.app.json 是否覆盖 tsconfig.json
    【解决方案2】:

    不同之处在于tsconfig.app.json 是一个与Angular 应用程序特别相关的文件,而tsconfig.json 是一个更通用的文件,包含通用的打字稿配置。当你有一个微前端系统时,它特别有用,其中有多个 Angular 子项目,每个子项目都有自己的 tsconfig.app.json 配置。但是,如果您愿意,可以将这两个文件完美地合并为一个,实际上您肯定注意到 tsconfig.app.json 包含以下行:

      "extends": "./tsconfig.json"
    

    表示整个App使用tsconfig.app.json中的配置加上tsconfig.json中的配置

    【讨论】:

      【解决方案3】:

      只想多加一点。

      似乎tsconfig.app.json(应用特定的)将覆盖tsconfig.json(全局的)。

      我的问题是来自 node 的类型声明不在我的 Angular 项目范围内,我收到编译错误,提示找不到 Buffer

      我首先在tsconfig.json 中添加了类型声明,认为它将在每个应用程序中生效。 但我必须将它添加到我的应用程序特定的 tsconfig.app.json 文件中才能在我的应用程序上生效。

      【讨论】:

        【解决方案4】:

        tsconfig.app.json 是 Angular 应用程序的配置,

        tsconfig.json 用于 IDE 集成

        tsconfig.json 可以删除

        根据https://github.com/angular/angular-cli/wiki/stories-rc.0-update#one-tsconfig-per-app

        【讨论】:

        • 那么这是否意味着 VSCode 忽略了tsconfig.app.json
        • tsconfig.json 在您将所有选项迁移到您的 tsconfig.app.json 之前无法删除,因为默认情况下后者从前者扩展。 "extends":"../tsconfig.json"
        猜你喜欢
        • 2018-05-01
        • 2022-08-05
        • 1970-01-01
        • 1970-01-01
        • 2017-05-10
        • 2017-10-08
        • 1970-01-01
        • 2018-10-11
        • 1970-01-01
        相关资源
        最近更新 更多