Shorten repeated local builds
Large applications
TypeScript · Const
Enables TypeScript to persist project-graph information between compilations. Later builds can reuse that information to reduce type-checking and emit work.
When enabled, TypeScript persists information about the project graph from the previous compilation. Later compilations use that cache to identify the least expensive type-checking and emit work, while the cache remains build-time data rather than runtime application data.
{
"compilerOptions": {
"incremental": true
}
}| Name | Type | Description |
|---|---|---|
incremental | boolean | Enables persistent project-graph information for reuse by subsequent compilations. |
{
"compilerOptions": {
"incremental": true,
"outDir": "./lib"
},
"include": ["./src"]
}Enable incremental compilation and place emitted files in lib; TypeScript stores build information there by default.
Large applications
Continuous integration
Monorepos
The incremental option makes TypeScript write project-graph information to disk so a later compilation can reuse it. This reduces the work needed for subsequent type-checking and emitting.
Follow-up: What happens if the cache is removed? The next build can recreate the .tsbuildinfo data and continue; the cache is not required by the emitted JavaScript.
By default, TypeScript creates .tsbuildinfo files in the same folder as the compilation output. Their location can be changed with tsBuildInfoFile.
Follow-up: Why might a team customize the location? A shared or dedicated build-cache directory can keep generated metadata separate from emitted artifacts.
The option is a boolean TSConfig setting: set incremental to true to enable it. A later invocation can then use the saved project-graph information.
Follow-up: How can a project choose a custom cache path? Set tsBuildInfoFile alongside incremental in compilerOptions.
tsBuildInfoFiletsc --buildproject references.tsbuildinfo