排除 tsconfig.json 中的子目录

exclude subdirectories in tsconfig.json

我已经安装了 TypeScript 1.8.2,并使用 Visual Studio 2015。我有一个简单的项目,在从 tsconfig.json 文件中排除文件夹时遇到问题。问题是我想排除文件 typings/browser.d.ts 和文件夹 typings/browser。但事实并非如此?

我排除子文件夹没有问题,但不是子文件夹?

[注意] 我刚刚意识到问题只出现在我从 Visual Studio 构建时!如果我从命令行使用 tsc 构建,就没有问题。我可以在 Visual Studio 中使用另一个版本的 TypeScript 吗?我该如何检查?

这是我的 tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "public",
    "typings/browser",
    "typings/browser.d.ts"
  ]
}

我有一个更大的项目,我在其中使用 jspm 并且需要排除 jspm 包文件夹,该文件夹位于 public 的子文件夹中。

试试:

 "exclude": [
     "node_modules",
     "public",
     "typings/browser.d.ts",
     "typings/browser/**"
 ]

我刚刚安装并测试了 Visual Studio 2015 的最新版 TypeScript(目前为 1.8.6),我可以确认此问题已在最新版本中得到修复。

https://www.microsoft.com/en-us/download/details.aspx?id=48593

[编辑] 确保还执行 npm update -g typescript

看起来这是打字稿无法排除属于更深层目录结构的 paths/patterns 的问题。它仍然是 "typescript@^3.4.5" 的问题。

为了解决这个问题,我开始在每次测试 运行.

之前用 "rimraf dist" 清理我的 Dist 目录
"test:unit": "npm run clean && stencil test --spec --snapshot",

我知道这是一个 hack,但有效。

我将 ts V4.1.3 与 webStorm 2021 一起使用,并排除了类似 tsconfig.json 中的 exclude:[server/**] 似乎没有排除,但我发现只有在编辑器中打开其中一个 ts 文件时才会编译。

我关闭了 WebStorm/File/Settings/Languages../TypeScript/Recompile On Changes 一切正常,即它不会编译服务器目录中任何级别的任何 ts 文件。