ScriptsApr 14, 2026·3 min read

tsup — Bundle Your TypeScript Library with Zero Config

tsup is the zero-config TypeScript bundler built on esbuild. It emits ESM, CJS, IIFE, and DTS files from a single command — the fastest way to ship a polished TypeScript package without writing Rollup config.

TL;DR
tsup bundles TypeScript libraries into ESM, CJS, and DTS outputs with zero configuration using esbuild.
§01

What it is

tsup is a zero-config TypeScript bundler built on esbuild. It produces ESM, CJS, IIFE, and declaration (DTS) files from a single command. tsup is the fastest way to ship a polished TypeScript package without writing Rollup, webpack, or esbuild configuration from scratch.

tsup targets library authors who need to publish TypeScript packages to npm. It handles the complexity of dual ESM/CJS output, type declarations, tree shaking, and source maps with sensible defaults.

§02

How it saves time or tokens

Configuring Rollup or webpack for a TypeScript library requires understanding module formats, declaration generation, and bundling strategies. tsup replaces all of that with a single command: tsup src/index.ts --format cjs,esm --dts. The esbuild backend makes compilation fast (typically under 1 second). DTS generation handles type declarations without a separate tsc step.

§03

How to use

  1. Install tsup:
npm install -D tsup
  1. Bundle your library:
npx tsup src/index.ts --format cjs,esm --dts
  1. Configure package.json exports:
{
  "main": "./dist/index.js",
  "module": "./dist/index.mjs",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.mjs",
      "require": "./dist/index.js"
    }
  }
}
§04

Example

// tsup.config.ts - Advanced configuration
import { defineConfig } from 'tsup';

export default defineConfig({
  entry: ['src/index.ts', 'src/cli.ts'],
  format: ['cjs', 'esm'],
  dts: true,
  splitting: true,
  sourcemap: true,
  clean: true,
  minify: true,
  target: 'es2020',
  external: ['react', 'react-dom'],
  banner: {
    js: '// Built with tsup',
  },
});
§05

Related on TokRepo

This tool integrates with standard development workflows and requires minimal configuration to get started. It is available as open-source software with documentation and community support through the official repository. The project follows semantic versioning for stable releases.

For teams evaluating this tool, the key advantage is reducing manual work in repetitive tasks. The automation provided by the built-in features means less custom code to maintain and fewer integration points to manage. This translates directly to lower maintenance costs and faster iteration cycles.

§06

Common pitfalls

  • DTS generation uses the TypeScript compiler internally and can be slow for large projects; use --dts only in production builds, not during watch mode.
  • esbuild does not type-check your code; run tsc --noEmit separately in CI to catch type errors that tsup will not report.
  • Some TypeScript features (const enums, namespaces) are not fully supported by esbuild; check the esbuild documentation for limitations.

Frequently Asked Questions

How is tsup different from tsc?+

tsc (TypeScript compiler) type-checks and emits JavaScript but does not bundle. tsup uses esbuild to bundle your code into optimized files with tree shaking, code splitting, and minification. tsup can also generate type declarations via a built-in tsc step.

Does tsup support watch mode?+

Yes. Run tsup with the --watch flag for automatic rebuilds on file changes. Watch mode is fast because esbuild's incremental compilation only reprocesses changed files.

Can tsup bundle multiple entry points?+

Yes. Specify multiple entry files in tsup.config.ts or on the command line. tsup generates separate output files for each entry point with proper code splitting.

Does tsup support CSS?+

tsup can process CSS imports via esbuild's built-in CSS support. For advanced CSS processing (PostCSS, Tailwind), use a separate build step or the postcss plugin.

Is tsup production-ready?+

Yes. tsup is used by many popular npm packages for their build process. It produces optimized output with source maps, minification, and proper module format support.

Citations (3)
  • tsup GitHub— tsup is a zero-config TypeScript bundler built on esbuild
  • tsup Documentation— tsup supports ESM, CJS, IIFE, and DTS output formats
  • esbuild GitHub— esbuild provides fast JavaScript/TypeScript bundling

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets