[英]How to exclude files ending in '.spec.ts' in tsconfig.json
I'm trying to include some files in my tsconfig.json, but it's including files I don't want to be included.我试图在我的 tsconfig.json 中包含一些文件,但它包含了我不想包含的文件。 From a repo (with uncompiled source) I'm trying to include files that end in
.ts
, except for ones that end in .spec.ts
.从存储库(带有未编译的源代码)中,我试图包含以
.ts
结尾的文件,但以.spec.ts
结尾的文件.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"],
(Then) new to Unix glob patterns/strings, I need ones to match and exclude the files correctly, and then how to add them to the config. (然后)Unix glob模式/字符串的新手,我需要正确匹配和排除文件,然后如何将它们添加到配置中。
TheTypeScript handbook has a good write up on tsconfig file . TypeScript 手册对 tsconfig 文件有很好的描述。
The example in the handbook is:手册中的例子是:
"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.您通常不需要更具体,因为我想您会希望排除“所有规范文件”,而不仅仅是特定子目录中的文件。
There are cases when this won't work.有些情况下这是行不通的。
tsc app.ts
(or pass other arguments) - your tsconfig is ignored when you do thistsc app.ts
(或传递其他参数)进行编译 - 执行此操作时会忽略您的 tsconfig您可以使用
"exclude": ["node_modules/dashboard/**/*.spec.ts"]
Changing to:更改为:
"include": ["node_modules/dashboard/**/*.ts"],
"exclude": ["node_modules/dashboard/**/*.spec.ts"],
will fix the problem.将解决问题。 From thedocumentation :
从文档:
* matches zero or more characters (excluding directory separators)
* 匹配零个或多个字符(不包括目录分隔符)
?? matches any one character (excluding directory separators)
匹配任何一个字符(不包括目录分隔符)
**/ recursively matches any subdirectory**/ 递归匹配任意子目录
It is the second use of ** that was causing too wide an inclusion to occur. ** 的第二次使用导致出现过宽的包含。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.