API Reference

tsup

Zero-config TypeScript bundler powered by esbuild that emits ESM and CJS plus type declarations in one command.

Official Documentation ↗
CompatibilityThis documentation covers version v8. Check the official docs for the latest API surface.

Installation

npmnpm install --save-dev tsup
pnpmpnpm add -D tsup

Methods

Overview

tsup is a zero-config TypeScript bundler built on esbuild that produces ESM, CommonJS, and declaration files with minimal setup. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • build — Runs a programmatic bundled build and resolves with per-entry results.
  • defineConfig — Type helper that provides editor autocompletion for the tsup config file.
  • tsup CLI — Command-line entry that bundles declared entries with format and declaration flags.

Example

const { build } = require('tsup');

await build({
  entry: ['src/index.ts'],
  format: ['esm', 'cjs'],
  dts: true,
  clean: true,
});

Notes

Dependencies stay external by default, which keeps bundles small but means consumers must install them. Enable dts and sourcemap for publishable packages.

Verification

Run a build with dts enabled and confirm both a .js and a .d.ts file appear in dist for each entry.

API reference evidence

Fetched from official sources on 2026-11-08T18:26:00+08:00 via WebFetch https://cdn.jsdelivr.net/gh/egoist/tsup@latest/README.md;WebFetch https://cdn.jsdelivr.net/npm/tsup@latest/dist/index.d.ts(官方文档站 https://tsup.egoist.dev/ 返回 NOT_FOUND,改用官方包内 .d.ts).

FAQ

How are type declarations generated?
Pass --dts on the CLI or dts: true in options; tsup runs a TypeScript declaration build alongside the esbuild bundle.
Does tsup bundle my dependencies?
Node dependencies are external by default so they are not inlined; list packages in noExternal to force bundling.
How do I produce both ESM and CJS from one config?
Set format to ["esm", "cjs"]; tsup emits matching extensions and can rewrite package.json exports when requested.