如何在tsconfig.json中排除以'.spec.ts'结尾的文件 [英] How to exclude files ending in '.spec.ts' in tsconfig.json

查看:692
本文介绍了如何在tsconfig.json中排除以'.spec.ts'结尾的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在tsconfig.json中包含一些文件,但它包含了我不想包含的文件。 (我看到搜索语法中使用的星号无处不在,但我不确定这个语法来自何处,以及在哪里可以了解更多信息。)从一个repo(带有未编译的源代码)我试图包含以 .ts ,但以 .spec.ts 结尾的除外。

I'm trying to include some files in my tsconfig.json, but it's including files I don't want to be included. (I see asterisks used in search syntax everywhere, but I'm not sure what this syntax is from, and where to learn more about it.) From a repo (with uncompiled source) I'm trying to include files that end in .ts, except for ones that end in .spec.ts.

以下内容包括我想要的文件,但未成功排除我不想要的文件。

The following includes the files I want, but doesn't successfully exclude the files I don't want.

  "include": ["node_modules/dashboard/**/*.ts"],
  "exclude": ["node_modules/dashboard/**/*.spec.ts"],

如何排除这些文件?

编辑:起初是使用 ** / **。ts ** / **。spec.ts 。这是不正确的,但现在我已经纠正了,我遇到了同样的问题。

At first was using **/**.ts and **/**.spec.ts. This was incorrect, but now that I've corrected it, I'm having the same issue.

推荐答案

TypeScript手册对tsconfig文件进行了很好的编写

手册中的示例是:

"exclude": [
    "node_modules",
    "**/*.spec.ts"
]

请注意,对于任何文件夹,使用 ** ,对于文件名通配符,请使用 * (单个星号)。

Note the use of ** for any folder, and * (a single asterisk) for the file name wildcard.

您通常不需要更具体,因为我想您会想要排除所有规范文件,而不仅仅是特定子目录中的文件。

You don't usually need to be any more specific, as I imagine you would want to exclude "all spec files", not just files in a particular sub-directory.

有些情况不起作用。


  1. 如果您还在include和exclude部分都包含该文件 - include wins

  2. 如果你是我将排除的文件导入包含的文件。

  3. 如果您使用的是旧版本的编译器(早期版本的tsconfig不允许使用通配符)

  4. 您正在使用 tsc app.ts 进行编译(或传递其他参数) - 执行此操作时将忽略您的tsconfig

  1. If you have also include the file in both include and exclude sections - include wins
  2. If you are importing the excluded file into an included file.
  3. If you are using an old version of the compiler (early versions of tsconfig didn't allow the wildcards)
  4. You are compiling using tsc app.ts (or pass other arguments) - your tsconfig is ignored when you do this

这篇关于如何在tsconfig.json中排除以'.spec.ts'结尾的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆