【问题标题】:TSC keeps creating subfolders in the 'outDir'TSC 不断在“outDir”中创建子文件夹
【发布时间】:2020-08-23 23:20:55
【问题描述】:

你好!

我正在使用 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

有人知道是什么导致了这个问题吗?

感谢您的各种帮助!提前谢谢各位!

【问题讨论】:

    标签: json typescript tsc tsconfig


    【解决方案1】:

    您需要将所有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

    【讨论】:

      猜你喜欢
      • 2018-05-31
      • 2020-03-22
      • 2018-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-24
      • 2016-12-09
      • 1970-01-01
      相关资源
      最近更新 更多