Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 7ae775a

Browse files
authored
Merge pull request #327 from Microsoft/globs_doc
Documentation for include and exclude globs in tsconfig.json
2 parents 937dea1 + 47cd655 commit 7ae775a

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

pages/tsconfig.json.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Example `tsconfig.json` files:
4545
}
4646
```
4747

48-
* Using the `"exclude"` property
48+
* Using the `"include"` and `"exclude"` properties
4949

5050
```json
5151
{
@@ -57,9 +57,12 @@ Example `tsconfig.json` files:
5757
"outFile": "../../built/local/tsc.js",
5858
"sourceMap": true
5959
},
60+
"include": [
61+
"src/**/*"
62+
],
6063
"exclude": [
6164
"node_modules",
62-
"wwwroot"
65+
"**/*.spec.ts"
6366
]
6467
}
6568
```
@@ -68,17 +71,28 @@ Example `tsconfig.json` files:
6871

6972
The `"compilerOptions"` property can be omitted, in which case the compiler's defaults are used. See our full list of supported [Compiler Options](./Compiler Options.md).
7073

71-
If no `"files"` property is present in a `tsconfig.json`, the compiler defaults to including all TypeScript (`*.ts` or `*.tsx`) files in the containing directory and subdirectories.
72-
When a `"files"` property is present, only the specified files are included.
74+
The `"files"` property takes a list of relative or absolute file paths.
75+
The `"include"` and `"exclude"` properties take a list of glob-like file patterns.
76+
The supported glob wildcards are:
7377

74-
If the `"exclude"` property is specified, the compiler includes all TypeScript (`*.ts` or `*.tsx`) files in the containing directory and subdirectories except for those files or folders that are excluded.
78+
* `*` matches zero or more characters (excluding directory separators)
79+
* `?` matches any one character (excluding directory separators)
80+
* `**/` recursively matches any subdirectory
7581

76-
The `"files"` property cannot be used in conjunction with the `"exclude"` property. If both are specified then the `"files"` property takes precedence.
82+
If a segment of a glob pattern includes only `*` or `.*`, then only files with supported extensions are included (e.g. `.ts`, `.tsx`, and `.d.ts` by default with `.js` and `.jsx` if `allowJs` is set to true).
7783

78-
Any files that are referenced by those specified in the `"files"` property are also included.
84+
If the `"files"` and `"include"` are both left unspecified, the compiler defaults to including all TypeScript (`.ts`, `.d.ts` and `.tsx`) files in the containing directory and subdirectories except those excluded using the `"exclude"` property. JS files (`.js` and `.jsx`) are also included if `allowJs` is set to true.
85+
If the `"files"` or `"include"` properties are specified, the compiler will instead include the union of the files included by those two properties.
86+
Files in the directory specified using the `"outDir"` compiler option are always excluded unless explicitly included via the `"files"` property (even when the "`exclude`" property is specified).
87+
88+
Files included using `"include"` can be filtered using the `"exclude"` property.
89+
However, files included explicitly using the `"files"` property are always included regardless of `"exclude"`.
90+
The `"exclude"` property defaults to excluding the `node_modules`, `bower_components`, and `jspm_packages` directories when not specified.
91+
92+
Any files that are referenced by files included via the `"files"` or `"include"` properties are also included.
7993
Similarly, if a file `B.ts` is referenced by another file `A.ts`, then `B.ts` cannot be excluded unless the referencing file `A.ts` is also specified in the `"exclude"` list.
8094

81-
A `tsconfig.json` file is permitted to be completely empty, which compiles all files in the containing directory and subdirectories with the default compiler options.
95+
A `tsconfig.json` file is permitted to be completely empty, which compiles all files included by default (as described above) with the default compiler options.
8296

8397
Compiler options specified on the command line override those specified in the `tsconfig.json` file.
8498

0 commit comments

Comments
 (0)