Technologies and Software Engineering

Incremental TypeScript Builds for Faster Compilation

Incremental compilation is a TypeScript build mode designed to speed up development by avoiding full project rebuilds on every compile.

Instead, the compiler tracks which files have changed since the previous build and recompiles only those files and their affected dependencies.

To support this, TypeScript stores build metadata in a .tsbuildinfo file, or in a custom file defined by the tsBuildInfoFile option. Reusing this information dramatically reduces rebuild times and can improve CI/CD performance when the build info file is cached between runs.

Basic Usage

To enable incremental compilation in a single TypeScript project, include the following in your tsconfig.json:

{
  "compilerOptions": {
    "incremental": true
  }
}

Running tsc will then perform fast incremental rebuilds. If the build information ever becomes outdated or corrupted, removing the generated .tsbuildinfo file will force a full rebuild.

Incremental Compilation in Project References

For larger, multi-package monorepos, TypeScript offers Project References, which create explicit build boundaries between sub-projects. When using project references:

tsc --build
tsc --build --clean

These commands work only when using project references and provide efficient, dependency-aware builds across multiple projects.

Tags:

Search