【问题标题】:How can I use project reference with difference tsconfig files?如何将项目引用与不同的 tsconfig 文件一起使用?
【发布时间】:2021-05-21 07:30:46
【问题描述】:

例如我有三个项目

shared
frontend
backend

我想在frontendbackend 中使用shared 项目作为项目参考

但是backend 使用commonjs 模块和前端使用esnext 模块,所以我希望shared 有两个配置tsconfig.commonjs.jsontsconfig.esmodules.json

如何将shared 用作backendtsconfig.commonjs.json 以及前端tsconfig.commonjs.json 中的参考项目

【问题讨论】:

    标签: node.js typescript commonjs project-reference


    【解决方案1】:

    我相信extends 选项是您正在寻找的。​​p>

    // tsconfig.shared.json
      "compilerOptions": {
         ...
      }
    ...
    
    // tsconfig.frontend.json
      "extends": "./tsconfig.shared",
      "compilerOptions": {
        "module": "esnext",
      }
    
    // tsconfig.backend.json
      "extends": "./tsconfig.shared",
      "compilerOptions": {
        "module": "commonjs",
      }
    

    【讨论】:

    • 当我使用 shared 作为参考项目时,使用这样的配置,它是用一个配置 tsconfig.shared.json 编译的
    猜你喜欢
    • 2019-02-15
    • 2021-09-10
    • 2022-11-04
    • 2014-06-14
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    相关资源
    最近更新 更多