Issue
I'm trying to include some files in my tsconfig.json, but it's including files I don't want to be included. 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"],
(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.
Solution
The TypeScript handbook has a good write up on tsconfig file.
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.
When This Won't Work
There are cases when this won't work.
- If you have also include the file in both include and exclude sections - include wins
- If you are importing the excluded file into an included file.
- If you are using an old version of the compiler (early versions of tsconfig didn't allow the wildcards)
- You are compiling using
tsc app.ts
(or pass other arguments) - your tsconfig is ignored when you do this
Answered By - Fenton
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.