Skip to main content

Lesson 5 of 8

Build Tools - tsc, Vite & esbuild

TypeScript source is compiled to JavaScript before running. The TypeScript compiler (`tsc`) is the reference implementation - but Vite (for browser) and esbuild (for Node) are dramatically faster alternatives for large codebases. Understanding when to use each and what they provide (or deliberately skip) is essential for toolchain setup.

11 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Build Tools - tsc vs Vite vs esbuild

Build Tools - tsc vs Vite vs esbuild
# ── tsc - TypeScript compiler (full type checking + emit) ────────
# Use when: you need type checking + compilation in one step,
#           generating .d.ts files for a library,
#           or running on its own without a bundler.

# Type check only (no emit - for CI):
npx tsc --noEmit

# Compile to JavaScript:
npx tsc # reads tsconfig.json, emits to outDir

# Watch mode (incremental):
npx tsc --watch

# ── esbuild - fast Node.js transpiler (NO type checking) ─────
# esbuild is 10-100x faster than tsc.
# It strips types without checking them (very fast, unsafe alone).
# Use alongside tsc --noEmit in CI for the safety net.

# npm install --save-dev esbuild tsx
# package.json:
# "dev":   "tsx watch src/index.ts"  → ts-node replacement, uses esbuild
# "build": "esbuild src/index.ts --bundle --platform=node --outfile=dist/index.js"

# Workflow: esbuild for speed, tsc for correctness in CI:
# "check":  "tsc --noEmit",          # type safety gate
# "build":  "npm run check && esbuild src/index.ts ..."

# ── Vite - browser bundler with TypeScript support ────────────
# Vite uses esbuild for dev (ultra-fast HMR), Rollup for production.
# TypeScript support is built-in - zero config.

# npm create vite@latest my-app -- --template react-ts
# Generates tsconfig.json, vite.config.ts, React+TS scaffold

# vite.config.ts:
import { defineConfig } from "vite";
import react              from "@vitejs/plugin-react";
import path               from "path";

export default defineConfig({
  plugins: [react()],
  resolve: { alias: { "@": path.resolve(__dirname, "./src") } },
  build: {
    target: "es2022",
    outDir: "dist",
    sourcemap: true,
  },
});

# package.json scripts (Vite project):
# "dev":          "vite"
# "build":        "tsc --noEmit && vite build"  ← type check THEN bundle
# "preview":      "vite preview"
# "type-check":   "tsc --noEmit"

# ── ts-reset (tsconfig enhancement) ──────────────────────────
# npm install --save-dev @total-typescript/ts-reset
# Add to any file in your project:
# import "@total-typescript/ts-reset";
# Effect: JSON.parse returns unknown (not any)
#         Array.filter(Boolean) correctly narrows types
#         fetch().json() returns unknown
# No runtime cost - purely type definitions.

Common Mistakes

  • Using only esbuild without `tsc --noEmit` in CI - esbuild strips types silently without checking them. Your code could have type errors and the build would still succeed. Always run `tsc --noEmit` as a gate in CI.
  • Running `tsc` in a Vite project for the build - Vite uses its own bundler (Rollup). In a Vite project, `tsc` is for type-checking only (`--noEmit`). The actual build command is `vite build`.
  • Forgetting `--noEmit` flag costs - running `tsc` without `--noEmit` writes output files to disk. In type-check-only contexts (CI, pre-commit hooks), always add `--noEmit` to avoid polluting the repo.

Tip

Tip

Practice Build Tools tsc Vite esbuild in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Visual architecture and concepts for Build Tools - tsc, Vite & esbuild

Practice Task

Note

Practice Task - (1) Write a working example of Build Tools tsc Vite esbuild from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Build Tools tsc Vite esbuild is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready typescript code.

Key Takeaways

  • TypeScript source is compiled to JavaScript before running.
  • Using only esbuild without `tsc --noEmit` in CI - esbuild strips types silently without checking them. Your code could have type errors and the build would still succeed. Always run `tsc --noEmit` as a gate in CI.
  • Running `tsc` in a Vite project for the build - Vite uses its own bundler (Rollup). In a Vite project, `tsc` is for type-checking only (`--noEmit`). The actual build command is `vite build`.
  • Forgetting `--noEmit` flag costs - running `tsc` without `--noEmit` writes output files to disk. In type-check-only contexts (CI, pre-commit hooks), always add `--noEmit` to avoid polluting the repo.

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/8 done