Boost Your Build Speed: Using TypeScript Incremental Compilation with Midway

This article explains how to enable TypeScript’s incremental compilation feature in a Midway project by adding the "incremental": true option to tsconfig.json, demonstrates the resulting tsconfig.tsbuildinfo file, shows faster subsequent builds, and introduces the new createIncrementalProgram API introduced in TypeScript 3.6 for programmatic incremental builds.

Node Underground
Node Underground
Node Underground
Boost Your Build Speed: Using TypeScript Incremental Compilation with Midway

Last month a Midway community member submitted a merge request that used a .tsbuildinfo file, which led us to discover TypeScript 3.4’s new incremental compilation feature.

We tested this with Midway’s scaffolding by adding "incremental": true to tsconfig.json:

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

Running npm run build then creates a tsconfig.tsbuildinfo file in the output directory (dist). This file stores version and signature information for later verification.

After modifying agent.ts and rebuilding, only tsconfig.tsbuildinfo changes while other compiled files (e.g., agent.js and its sourcemap) retain their timestamps, demonstrating a significant speed boost for subsequent builds.

In everyday development we often run TypeScript files directly, so the benefit is most noticeable when a full local build is required. Additionally, using tsc in watch mode provides incremental compilation that works well with editor auto‑save.

TypeScript 3.6, released at the end of August, expands the incremental compilation API. Besides the traditional createProgram, you can now use createIncrementalProgram and createIncrementalCompilerHost to control incremental builds programmatically.

Example using the new API:

import * as ts from "typescript";

const program = ts.createIncrementalProgram({
  rootNames: ["./src/foo.ts"],
  options: {
    incremental: true,
    tsBuildInfoFile: "./tsbuildinfo"
  }
});
const emit = program.emit();
console.log('emitted', JSON.stringify(emit));

Running this code compiles the source and generates the tsbuildinfo file, confirming that incremental compilation is enabled.

We only performed a simple test of the new API, but it shows Microsoft’s effort to improve compilation speed and usability for JavaScript developers, and we look forward to further enhancements in future TypeScript releases.

Click the original article to learn more about the changes in TypeScript 3.6.

TypeScriptbuild optimizationMidwayincremental-compilationcreateIncrementalProgram
Node Underground
Written by

Node Underground

No language is immortal—Node.js isn’t either—but thoughtful reflection is priceless. This underground community for Node.js enthusiasts was started by Taobao’s Front‑End Team (FED) to share our original insights and viewpoints from working with Node.js. Follow us. BTW, we’re hiring.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.