javascript - Typescript tsconfig 排除一些源文件

标签 javascript typescript tsconfig transpiler

我试图让 Typescript 在编译时排除某些文件。但是,它似乎并不想排除它们。

这是我的 tsconfig.json

{
  "ref": "master",
  "path": "typings",
  "compilerOptions": {
    "module": "amd",
    "target": "es5",
    "declaration": true,
    "sourceMap": true,
    "outDir": "build/src"
  },
  "exclude": [
    "node_modules",
    "typings/global",
    "typings/index.d.ts",
    "./src/subClassA.ts"
  ],
  "files": [
    "./src/entry.ts"
  ]
}

它似乎排除了 node_modules 和 typings。但是编译后的代码,仍然包含 subClassA。

我原以为编译后的代码没有任何来自 subClassA 的代码,但它确实有。

最佳答案

来自documentation :

Any files that are referenced by files included via the "files" or "include" properties are also included. Similarly, if a file B.ts is referenced by another file A.ts, then B.ts cannot be excluded unless the referencing file A.ts is also specified in the "exclude" list.

如果您的./src/entry.ts 文件或./src/entry.ts 的任何依赖项使用./src/subClassA.ts 某处,则 ./src/subClassA.ts 不能被排除,除非 ./src/entry.ts 也被排除。

相关讨论:https://github.com/Microsoft/TypeScript/issues/7432

关于javascript - Typescript tsconfig 排除一些源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43538650/

相关文章:

javascript - 将按钮添加到新元素

javascript - 在 Controller 类中实现后退按钮

Typescript 找不到已与 SystemJS 映射的模块

typescript - tsc 命令没有编译到 outDir

javascript - 为什么 push 显示 argument of type 'any[]' is not assignable to parameter of type 'never' 错误?

javascript - 为什么浏览器在经过身份验证的 XMLHttpRequest 之后不重用授权 header ?

typescript - 如何使用 Sapper 在 Svelte 文件中导入/导出 Typescript 类型/接口(interface)?

typescript - 在 TypeScript 中创建 "fake"新类型

javascript - 特定字符的 TypeScript 类型字符串

Angular5 - TypeScript 编译中缺少文件