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.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install dce122a2-37be-11f1-9bc6-00163e2b0d79 --target codex先 dry-run 确认安装计划,再运行此命令。
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.
常见问题
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.
引用来源 (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
讨论
相关资产
vanilla-extract — Zero-Runtime Type-Safe CSS in TypeScript
A CSS-in-TypeScript framework that generates static CSS files at build time, giving you type-safe style authoring with zero runtime cost and standard CSS output.
Naive UI — Complete Vue 3 Component Library with TypeScript
Naive UI is a fully tree-shakable Vue 3 component library written in TypeScript. It ships over 90 components with built-in dark mode, customizable theming, and first-class TypeScript support, making it a strong choice for building modern web applications.
ArkType — TypeScript's 1:1 Validator with Instant Inference
Runtime validation library that mirrors TypeScript syntax for schemas with zero-overhead type inference.
Better Auth — Framework-Agnostic Authentication for TypeScript
Better Auth is a comprehensive TypeScript authentication library that provides email/password, OAuth, multi-factor, and session management out of the box. It works with any framework and any database, offering a plugin system for extending authentication flows without vendor lock-in.