talira

ts-loader

The TypeScript loader for webpack: compile .ts and .tsx files as part of a webpack build

open sourceMITfree

ts-loader is the TypeScript loader for webpack: it runs the TypeScript compiler on .ts and .tsx files during a webpack build, reports type errors and can emit declaration files. For faster builds it has a transpile-only mode that skips type checking, meant to be paired with fork-ts-checker-webpack-plugin, which checks types in a separate process. It supports TypeScript project references, Yarn Plug'n'Play, hot module replacement and webpack watch mode, and works alongside Babel and babel-loader.

Problems it solves

  • compile TypeScript as part of my webpack build
  • my webpack build with TypeScript is slow because it type-checks every file on each rebuild
  • use TypeScript project references in a webpack project

Features

  • Compiles TypeScript (.ts, .tsx) inside a webpack build
  • Reports type errors and fails the build on them
  • transpileOnly mode for fast builds, with type checking moved to fork-ts-checker-webpack-plugin
  • Emits declaration (.d.ts) files
  • Incremental builds with TypeScript project references
  • Works with Babel, Yarn Plug'n'Play, webpack watch and hot module replacement

Limitations

  • transpileOnly mode skips type checking and emits no declaration files unless a separate checker such as fork-ts-checker-webpack-plugin is set up1

Alternatives

The same job

These do what ts-loader does.

  1. webpack A bundler for javascript and friends
  2. SWC Rust-based platform for the Web: a super-fast TypeScript and JavaScript compiler
  3. tsup Zero-config bundler for TypeScript libraries, powered by esbuild
  4. esbuild An extremely fast bundler for the web
  5. Parcel The zero configuration build tool for the web
  6. Rspack Fast Rust-based web bundler with a webpack-compatible API

Compare ts-loader with the top 3