← Back to TypeScript Course | Chapter 26: Monorepos and Large Projects | Lesson 4 of 5

Incremental Compilation की जानकारी

Incremental compilation TypeScript को पिछले builds की information reuse करने देता है। यह बड़े projects में repeated builds को तेज़ बना सकता है।
Syntax
typescript
{
  "compilerOptions": {
    "incremental": true,
    "tsBuildInfoFile": "./.tsbuildinfo"
  }
}

Core Concept

Incremental compilation tsc से एक .tsbuildinfo file save करवाता है जो record करती है कि कौन सी files check हुई थीं और वे किस पर depend करती हैं, इसलिए एक बाद का compile scratch से पूरे project के बजाय सिर्फ उन files को re-check करता है जो असल में बदली।

उदाहरण: Core Concept

typescript
// tsconfig.json: { "compilerOptions": { "incremental": true } }
// Produces a .tsbuildinfo file tracking what's already been checked.
console.log("Incremental builds only re-check files that actually changed");

Basic Setup

इसे enable करना एक single tsconfig.json flag है: "incremental": true (या यह automatically implied होता है जब project references के लिए "composite": true set हो)।

उदाहरण: Basic Setup

typescript
// tsconfig.json
// { "compilerOptions": { "incremental": true, "tsBuildInfoFile": "./.tsbuildinfo" } }
console.log("A single flag enables incremental compilation");

Typed Example

एक typed example: एक बड़े project पर, पहला tsc run 20 seconds ले सकता है, लेकिन एक file edit करने के बाद दूसरा run एक second से कम में complete होता है, क्योंकि सिर्फ वह file और इसके dependents re-type-check होते हैं।

उदाहरण: Typed Example

typescript
// First tsc run: 20s. Edit one file, run again: under 1s.
console.log("Only the changed file and its dependents get re-checked");

Project Usage

एक असली project में, incremental compilation को watch mode (tsc --watch) के साथ combine करना वह है जो एक बड़े codebase के edit-save-recheck loop को हर keystroke के बाद multi-second wait force करने के बजाय instant feel कराता है।

उदाहरण: Project Usage

typescript
// tsc --watch + incremental: true makes the edit-save loop feel instant
console.log("Watch mode plus incremental builds speeds up large codebases");

Best Practices

.tsbuildinfo को version control में commit करें सिर्फ तब अगर आपका CI setup इसे runs के बीच reliably restore कर सके; नहीं तो इसे git से exclude करें और हर fresh CI run को one-time full-compile cost pay होने दें।

उदाहरण: Best Practices

typescript
// .gitignore: .tsbuildinfo   (unless CI can reliably cache it)
console.log("Only commit .tsbuildinfo if your CI can restore it between runs");
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. .tsbuildinfo file delete करना या commit करना, इसलिए incremental builds फिर से शुरू होते हैं या stale data उपयोग करते हैं।
  2. यह उम्मीद करना कि incremental पहले build को तेज़ करेगा, जब सिर्फ बाद के builds को फायदा होता है।
  3. --noEmit को incremental के साथ उपयोग करना बिना tsBuildInfoFile set किए, उन versions में जहां इसकी ज़रूरत है।
🔒

Chapter Quiz — Complete all 5 topics to unlock

0/5 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.