typescript - 包含路径中的类型,但不编译它们

问题描述 投票:0回答:1

我在打字稿中遇到了一个问题。我有以下层次结构:

.
+-- @types
|   +-- declaration1.ts
|   +-- declaration2.ts
+-- common
|   +-- utils1.ts
|   +-- utils2.ts
+-- tests
|   +-- utils1.test.ts
|   +-- utils2.test.ts

在我的tsconfig.json中,我把这个配置放在测试和公共(或vscode抱怨)中暴露我的所有类型:

{
  "compilerOptions": {
    "outDir": "build/",
  },
  "include": ["tests", "common", "@types"]
}

我的问题是,我不想编译所有这些东西,我只想编译公共(这是utils,我不能得到一个(甚至多个)入口点)。

所以我想键入tsc并获得一个build文件夹填充如下:

.
+-- build
|   +-- common
|   |   +-- utils1.js
|   |   +-- utils2.js
// nothing else

相反,我得到了这个:

.
+-- build
|   +-- @types
|   |   +-- declaration1.js
|   |   +-- declaration2.js
|   +-- common
|   |   +-- utils1.js
|   |   +-- utils2.js
|   +-- tests
|   |   +-- utils1.test.js
|   |   +-- utils2.test.js

我无法得到如何从编译中排除这个目录。

谢谢,如果有人有想法。

typescript typescript-typings
1个回答
0
投票

要包含类型但不编译它们,请将它们添加到"typeRoots"中的tsconfig.json"include"中的所有内容都将被编译。

{
  "compilerOptions": {
    "typeRoots": [ "@types", "tests" ]
  }
}

要忽略文件或目录,请使用"exclude"选项,例如:

{
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.