TSC不断在“ outDir”中创建子文件夹

问题描述

你好!

我正在使用TypeScript进行一个小型项目,该项目要求我有两个不同的tsconfig.json文件,这两个文件都继承自我的tsconfig.base.json文件

我遇到了编译器在声明的outDir中创建子文件夹的问题,这有点使我发疯。

这是我的tsconfig.base.json文件

{
    "compilerOptions": {
      "target": "es6","module": "commonjs","resolveJsonModule": true,"lib": ["es6","dom"],"esModuleInterop": true,},"exclude": [
      "node_modules"
    ]
}

这是派生的tsconfig.src.json的样子:

{
    "extends": "./tsconfig.base.json","compilerOptions": {
        "rootDirs": ["./src/ts","."],"outDir": "./src/js/"
    },"exclude": [
        "page/**/*.ts","tsconfig.page.json"
    ],"include": [
        "src/**/*.ts","service_account.json"
    ],}

我当前的项目结构如下:

.
+-- node_modules/
+-- src/
|    +-- js/ (this is where my typescript files should be compiled to)
|    +-- ts/ (this is where all my ts files are located)
+-- tsconfig.base.json
+-- tsconfig.src.json
+-- service_account.json

现在,如果我运行build:backend脚本("build:backend": "tsc -p ./tsconfig.source.json"),则编译器将创建两个子文件夹,这将使我的项目结构如下所示:

.
+-- node_modules/
+-- src/
|    +-- js/ (this is where my typescript files should be compiled to)
|        +-- src/
|            +-- ts/ (here are all compiled js files Now)
|    +-- ts/ (this is where all my ts files are located)
+-- tsconfig.base.json
+-- tsconfig.src.json
+-- service_account.json

有人知道导致这个问题的原因吗?

我非常感谢您的各种帮助!预先感谢大家!

解决方法

您需要将所有inputs合并到一个文件夹中,并将所有outputs合并到inputs文件夹中没有包含的文件夹 中。

示例修复程序

{
    "extends": "./tsconfig.base.json","compilerOptions": {
        "rootDir": "/src/ts","outDir": "./src/js"
    },"exclude": [
        "page/**/*.ts","tsconfig.page.json"
    ]
}

并将service_account.json也移到src/ts