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.
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.
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.
How to use
- Install tsup:
npm install -D tsup
- Bundle your library:
npx tsup src/index.ts --format cjs,esm --dts
- 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"
}
}
}
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',
},
});
Related on TokRepo
- AI Tools for Coding — Developer tools and build systems
- Featured Workflows — Top-rated development tools
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.
Common pitfalls
- DTS generation uses the TypeScript compiler internally and can be slow for large projects; use
--dtsonly in production builds, not during watch mode. - esbuild does not type-check your code; run
tsc --noEmitseparately 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
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.
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.
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.
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.
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
Related on TokRepo
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.