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

Documentation for include and exclude globs in tsconfig.json #327

Merged
merged 4 commits into from
Jun 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions pages/tsconfig.json.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Example `tsconfig.json` files:
}
```

* Using the `"exclude"` property
* Using the `"include"` and `"exclude"` properties

```json
{
Expand All @@ -57,9 +57,12 @@ Example `tsconfig.json` files:
"outFile": "../../built/local/tsc.js",
"sourceMap": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"wwwroot"
"**/*.spec.ts"
]
}
```
Expand All @@ -68,17 +71,28 @@ Example `tsconfig.json` files:

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).

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.
When a `"files"` property is present, only the specified files are included.
The `"files"` property takes a list of relative or absolute file paths.
The `"include"` and `"exclude"` properties take a list of glob-like file patterns.
The supported glob wildcards are:

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.
* `*` matches zero or more characters (excluding directory separators)
* `?` matches any one character (excluding directory separators)
* `**/` recursively matches any subdirectory

The `"files"` property cannot be used in conjunction with the `"exclude"` property. If both are specified then the `"files"` property takes precedence.
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).

Any files that are referenced by those specified in the `"files"` property are also included.
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.
If the `"files"` or `"include"` properties are specified, the compiler will instead include the union of the files included by those two properties.
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).

Files included using `"include"` can be filtered using the `"exclude"` property.
However, files included explicitly using the `"files"` property are always included regardless of `"exclude"`.
The `"exclude"` property defaults to excluding the `node_modules`, `bower_components`, and `jspm_packages` directories when not specified.

Any files that are referenced by files included via the `"files"` or `"include"` properties are also included.
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.

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.
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.

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

Expand Down