Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  60] [ 7]  / answers: 1 / hits: 35750  / 6 Years ago, thu, january 25, 2018, 12:00:00

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.


More From » angular

 Answers
15

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.




  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


[#55359] Tuesday, January 23, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
patienceannel

Total Points: 674
Total Questions: 101
Total Answers: 101

Location: Northern Mariana Islands
Member since Fri, Jan 15, 2021
3 Years ago
patienceannel questions
Fri, Mar 11, 22, 00:00, 2 Years ago
Tue, Oct 20, 20, 00:00, 4 Years ago
Wed, Jul 24, 19, 00:00, 5 Years ago
;