Course contentsShow
← TypeScript
Lesson 76 of 1,7962. Setup and ToolingFree lesson

Understanding Compilation Modes: Build vs Watch vs Project

Learn the three primary modes TypeScript runs in and when to use --build, --watch, or standard compilation.

Understanding Compilation Modes: Build vs Watch vs Project

What you'll learn: How to choose between TypeScript's three primary compilation modes based on your development needs.

The Core Idea

When you run tsc, TypeScript offers three distinct modes that control how and when your code gets compiled. Think of them like different speed settings on a kitchen appliance—each serves a specific purpose:

  • Standard mode (tsc): Compile once and stop
  • Watch mode (tsc --watch): Compile once, then recompile automatically when files change
  • Build mode (tsc --build): Compile multiple related projects efficiently

Standard Compilation

Running tsc by itself compiles your TypeScript files according to your tsconfig.json and then exits. This is perfect for:

  • Production builds
  • CI/CD pipelines
  • One-time compilation tasks

Watch Mode

Using tsc --watch keeps the compiler running in the background, monitoring your files for changes. When you save a file, TypeScript instantly recompiles. This is ideal for:

  • Active development sessions
  • Getting immediate feedback on type errors
  • Avoiding manual recompilation

You've already encountered this—it's the same watch behavior you saw in the "Watching Files with tsc --watch" lesson.

Build Mode

The tsc --build (or tsc -b) mode is designed for project references—when you have multiple tsconfig.json files that depend on each other. It intelligently:

  • Only recompiles what changed
  • Respects dependencies between projects
  • Caches compilation results

This becomes valuable in larger codebases or monorepos where rebuilding everything would be slow.

Key Takeaway: Use standard tsc for single builds, --watch for active development with auto-recompilation, and --build for managing multi-project TypeScript workspaces efficiently.