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.
Ready-to-run agent install
This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.
npx -y tokrepo@latest install dce122a2-37be-11f1-9bc6-00163e2b0d79 --target codexRun after dry-run confirms the install plan.
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
Parcel — Zero Configuration Web Application Bundler
Parcel is a zero-configuration build tool for the web that automatically handles JavaScript, CSS, HTML, images, and more. It features blazing-fast builds using Rust and multicore processing, with no config files needed to get started.
Microbundle — Zero-Configuration Bundler for Tiny JavaScript Modules
A zero-configuration bundler for small JavaScript and TypeScript libraries. Microbundle produces modern ESM, CJS, and UMD outputs from a single source with automatic minification.
AppImageKit — Bundle Linux Apps That Run Anywhere
AppImageKit provides the tools to package Linux desktop applications into self-contained AppImage files that run on any distribution without installation or root access.
Turbopack — Rust-Powered Incremental Bundler for JavaScript and TypeScript
Turbopack is a Rust-based incremental bundler for JavaScript and TypeScript projects, designed as the successor to Webpack. It is integrated into Next.js for development builds.