76

Is there any way to add a pattern in the exclude property of a tsconfig file or is it only able to support directories?

I'm trying to exclude all my test files from compilation so I was wondering if I can use something like this :

src/**/*.spec.ts

Seems like it doesn't work though.

Liam
  • 27,717
  • 28
  • 128
  • 190
Nick Tsitlakidis
  • 2,269
  • 3
  • 22
  • 26

2 Answers2

90

Full example if anyone needs it:

{
  "compilerOptions": {
    ...
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "src/**/*.spec.ts"
  ]
}
sherb
  • 5,845
  • 5
  • 35
  • 45
  • 1
    The test files in the output directory has to be cleared! Else the test will still keep checking them – mykoman Nov 13 '21 at 09:50
65

Globs work in Typescript 2.0+. You would do "exclude" : ["src/**/*.spec.ts"] in your tsconfig.json.

More

https://basarat.gitbook.io/typescript/content/docs/project/files.html

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
basarat
  • 261,912
  • 58
  • 460
  • 511