Exclude with pattern in tsconfig.json

TypescriptTsconfig

Typescript Problem Overview


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.

Typescript Solutions


Solution 1 - Typescript

Full example if anyone needs it:

{
  "compilerOptions": {
    ...
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "src/**/*.spec.ts"
  ]
}

Solution 2 - Typescript

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNick TsitlakidisView Question on Stackoverflow
Solution 1 - TypescriptsherbView Answer on Stackoverflow
Solution 2 - TypescriptbasaratView Answer on Stackoverflow