tsdown by rolldown/tsdown
npx skills add https://github.com/rolldown/tsdown --skill tsdown基于 Rolldown 和 Oxc 的极速 TypeScript/JavaScript 库打包工具。
# 安装
pnpm add -D tsdown
# 基本用法
npx tsdown
# 使用配置文件
npx tsdown --config tsdown.config.ts
# 监听模式
npx tsdown --watch
# 从 tsup 迁移
npx tsdown-migrate
import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['./src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
clean: true,
})
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 快速开始 | 安装、首次打包、CLI 基础 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 配置文件 | 配置文件格式、多配置、工作区 | option-config-file |
| CLI 参考 | 所有 CLI 命令和选项 | reference-cli |
| 从 tsup 迁移 | 迁移指南和兼容性说明 | guide-migrate-from-tsup |
| 插件 | Rolldown、Rollup、Unplugin 支持 | advanced-plugins |
如需包含完整选项映射的综合迁移帮助,请安装专用的
tsdown-migrate技能:npx skills add rolldown/tsdown --skill tsdown-migrate
| 钩子 | 自定义逻辑的生命周期钩子 | advanced-hooks |
| 编程式 API | 从 Node.js 脚本构建 | advanced-programmatic |
| Rolldown 选项 | 直接传递选项给 Rolldown | advanced-rolldown-options |
| CI 环境 | CI 检测、'ci-only' / 'local-only' 值 | advanced-ci |
| 选项 | 用法 | 参考链接 |
|---|---|---|
| 入口点 | entry: ['src/*.ts', '!**/*.test.ts'] | option-entry |
| 输出格式 | format: ['esm', 'cjs', 'iife', 'umd'] | option-output-format |
| 输出目录 | outDir: 'dist', outExtensions | option-output-directory |
| 类型声明 | dts: true, dts: { sourcemap, compilerOptions, vue } | option-dts |
| 目标环境 | target: 'es2020', target: 'esnext' | option-target |
| 平台 | platform: 'node', platform: 'browser' | option-platform |
| 摇树优化 | treeshake: true, 自定义选项 | option-tree-shaking |
| 压缩 | minify: true, minify: 'dce-only' | option-minification |
| 源码映射 | sourcemap: true, 'inline', 'hidden' | option-sourcemap |
| 监听模式 | watch: true, 监听选项 | option-watch-mode |
| 清理 | clean: true, 清理模式 | option-cleaning |
| 日志级别 | logLevel: 'silent', failOnWarn: false | option-log-level |
| 功能 | 用法 | 参考链接 |
|---|---|---|
| 永不打包 | deps: { neverBundle: ['react', /^@myorg\//] } | option-dependencies |
| 始终打包 | deps: { alwaysBundle: ['dep-to-bundle'] } | option-dependencies |
| 仅打包 | deps: { onlyBundle: ['cac', 'bumpp'] } - 白名单 | option-dependencies |
| 跳过 node_modules | deps: { skipNodeModulesBundle: true } | option-dependencies |
| 自动外部化 | 自动依赖/peer/可选依赖外部化 | option-dependencies |
| 功能 | 用法 | 参考链接 |
|---|---|---|
| 垫片 | shims: true - 添加 ESM/CJS 兼容性 | option-shims |
| CJS 默认导出 | cjsDefault: true (默认) / false | option-cjs-default |
| 包导出 | exports: true - 自动生成 exports 字段 | option-package-exports |
| CSS 处理 | [实验性] css: { ... } — 包含预处理器、Lightning CSS、PostCSS、CSS 模块、代码分割的完整管道;需要 @tsdown/css | option-css |
| CSS 模块 | css: { modules: { localsConvention: 'camelCase' } } — 为 .module.css 文件提供作用域类名 | option-css |
| CSS 注入 | css: { inject: true } — 在 JS 输出中保留 CSS 导入 | option-css |
| 非打包模式 | unbundle: true - 保留目录结构 | option-unbundle |
| 根目录 | root: 'src' - 控制输出目录映射 | option-root |
| 可执行文件 | [实验性] exe: true - 打包为独立可执行文件,通过 @tsdown/exe 跨平台 | option-exe |
| 包验证 | publint: true, attw: true - 验证包 | option-lint |
| 框架 | 指南 | 参考链接 |
|---|---|---|
| React | JSX 转换、React 编译器 | recipe-react |
| Vue | SFC 支持、JSX | recipe-vue |
| Solid | SolidJS JSX 转换 | recipe-solid |
| Svelte | Svelte 组件库(推荐源码分发) | recipe-svelte |
| WASM | 通过 rolldown-plugin-wasm 支持 WebAssembly 模块 | recipe-wasm |
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
clean: true,
})
export default defineConfig({
entry: {
index: 'src/index.ts',
utils: 'src/utils.ts',
cli: 'src/cli.ts',
},
format: ['esm', 'cjs'],
dts: true,
})
export default defineConfig({
entry: ['src/index.ts'],
format: ['iife'],
globalName: 'MyLib',
platform: 'browser',
minify: true,
})
export default defineConfig({
entry: ['src/index.tsx'],
format: ['esm', 'cjs'],
dts: true,
deps: {
neverBundle: ['react', 'react-dom'],
},
inputOptions: {
jsx: { runtime: 'automatic' },
},
})
export default defineConfig({
entry: ['src/**/*.ts', '!**/*.test.ts'],
unbundle: true, // 保留文件结构
format: ['esm'],
dts: true,
})
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
failOnWarn: 'ci-only', // 可选:在 CI 中对警告报错
publint: 'ci-only',
attw: 'ci-only',
})
import { wasm } from 'rolldown-plugin-wasm'
import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['src/index.ts'],
plugins: [wasm()],
})
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
target: 'chrome100',
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "src/styles/variables" as *;`,
},
},
},
})
export default defineConfig({
entry: ['src/cli.ts'],
exe: true,
})
@tsdown/exe)export default defineConfig({
entry: ['src/cli.ts'],
exe: {
targets: [
{ platform: 'linux', arch: 'x64', nodeVersion: '25.7.0' },
{ platform: 'darwin', arch: 'arm64', nodeVersion: '25.7.0' },
{ platform: 'win', arch: 'x64', nodeVersion: '25.7.0' },
],
},
})
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
hooks: {
'build:before': async (context) => {
console.log('Building...')
},
'build:done': async (context) => {
console.log('Build complete!')
},
},
})
导出数组以实现多个构建配置:
export default defineConfig([
{
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
},
{
entry: ['src/cli.ts'],
format: ['esm'],
platform: 'node',
},
])
使用函数实现动态配置:
export default defineConfig((options) => {
const isDev = options.watch
return {
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
minify: !isDev,
sourcemap: isDev,
}
})
使用通配符模式构建多个包:
export default defineConfig({
workspace: 'packages/*',
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
})
# 基本命令
tsdown # 构建一次
tsdown --watch # 监听模式
tsdown --config custom.ts # 自定义配置
npx tsdown-migrate # 从 tsup 迁移
# 输出选项
tsdown --format esm,cjs # 多种格式
tsdown -d lib # 自定义输出目录 (--out-dir)
tsdown --minify # 启用压缩
tsdown --dts # 生成声明文件
tsdown --exe # 打包为独立可执行文件
tsdown --unbundle # 无打包模式
# 入口选项
tsdown src/index.ts # 单个入口
tsdown src/*.ts # 通配符模式
tsdown src/a.ts src/b.ts # 多个入口
# 工作区 / 单体仓库
tsdown -W # 启用工作区模式
tsdown -W -F my-package # 过滤特定包
tsdown --filter /^pkg-/ # 按正则过滤
# 开发
tsdown --watch # 监听模式
tsdown --sourcemap # 生成源码映射
tsdown --clean # 清理输出目录
tsdown --from-vite # 复用 Vite 配置
tsdown --tsconfig tsconfig.build.json # 自定义 tsconfig
始终为 TypeScript 库生成类型声明:
{ dts: true }
外部化依赖以避免打包不必要的代码:
{ deps: { neverBundle: [/^react/, /^@myorg\//] } }
使用摇树优化以获得最佳打包大小:
{ treeshake: true }
为生产构建启用压缩:
{ minify: true }
添加垫片以获得更好的 ESM/CJS 兼容性:
{ shims: true } // 添加 __dirname, __filename 等
自动生成 package.json 导出:
{ exports: true } // 创建正确的 exports 字段
在开发期间使用监听模式:
tsdown --watch
为包含许多文件的工具保留结构:
{ unbundle: true } // 保持目录结构
在发布前于 CI 中验证包:
{ publint: 'ci-only', attw: 'ci-only' }
每周安装量
430
仓库
GitHub 星标
3.7K
首次出现
2026年1月29日
安全审计
安装于
codex387
opencode383
github-copilot382
gemini-cli374
amp358
kimi-cli355
Blazing-fast bundler for TypeScript/JavaScript libraries powered by Rolldown and Oxc.
# Install
pnpm add -D tsdown
# Basic usage
npx tsdown
# With config file
npx tsdown --config tsdown.config.ts
# Watch mode
npx tsdown --watch
# Migrate from tsup
npx tsdown-migrate
import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['./src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
clean: true,
})
| Topic | Description | Reference |
|---|---|---|
| Getting Started | Installation, first bundle, CLI basics | guide-getting-started |
| Configuration File | Config file formats, multiple configs, workspace | option-config-file |
| CLI Reference | All CLI commands and options | reference-cli |
| Migrate from tsup | Migration guide and compatibility notes | guide-migrate-from-tsup |
| Plugins | Rolldown, Rollup, Unplugin support | advanced-plugins |
For comprehensive migration assistance with complete option mappings, install the dedicated
tsdown-migrateskill:npx skills add rolldown/tsdown --skill tsdown-migrate| Hooks | Lifecycle hooks for custom logic | advanced-hooks | | Programmatic API | Build from Node.js scripts | advanced-programmatic | | Rolldown Options | Pass options directly to Rolldown | advanced-rolldown-options | | CI Environment | CI detection,'ci-only'/'local-only'values | advanced-ci |
| Option | Usage | Reference |
|---|---|---|
| Entry points | entry: ['src/*.ts', '!**/*.test.ts'] | option-entry |
| Output formats | format: ['esm', 'cjs', 'iife', 'umd'] | option-output-format |
| Output directory | outDir: 'dist', outExtensions | option-output-directory |
| Type declarations |
| Feature | Usage | Reference |
|---|---|---|
| Never bundle | deps: { neverBundle: ['react', /^@myorg\//] } | option-dependencies |
| Always bundle | deps: { alwaysBundle: ['dep-to-bundle'] } | option-dependencies |
| Only bundle | deps: { onlyBundle: ['cac', 'bumpp'] } - Whitelist | option-dependencies |
| Skip node_modules | deps: { skipNodeModulesBundle: true } |
| Feature | Usage | Reference |
|---|---|---|
| Shims | shims: true - Add ESM/CJS compatibility | option-shims |
| CJS default | cjsDefault: true (default) / false | option-cjs-default |
| Package exports | exports: true - Auto-generate exports field | option-package-exports |
| CSS handling | — full pipeline with preprocessors, Lightning CSS, PostCSS, CSS modules, code splitting; requires |
| Framework | Guide | Reference |
|---|---|---|
| React | JSX transform, React Compiler | recipe-react |
| Vue | SFC support, JSX | recipe-vue |
| Solid | SolidJS JSX transform | recipe-solid |
| Svelte | Svelte component libraries (source distribution recommended) | recipe-svelte |
| WASM | WebAssembly modules via rolldown-plugin-wasm | recipe-wasm |
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
clean: true,
})
export default defineConfig({
entry: {
index: 'src/index.ts',
utils: 'src/utils.ts',
cli: 'src/cli.ts',
},
format: ['esm', 'cjs'],
dts: true,
})
export default defineConfig({
entry: ['src/index.ts'],
format: ['iife'],
globalName: 'MyLib',
platform: 'browser',
minify: true,
})
export default defineConfig({
entry: ['src/index.tsx'],
format: ['esm', 'cjs'],
dts: true,
deps: {
neverBundle: ['react', 'react-dom'],
},
inputOptions: {
jsx: { runtime: 'automatic' },
},
})
export default defineConfig({
entry: ['src/**/*.ts', '!**/*.test.ts'],
unbundle: true, // Preserve file structure
format: ['esm'],
dts: true,
})
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
failOnWarn: 'ci-only', // opt-in: fail on warnings in CI
publint: 'ci-only',
attw: 'ci-only',
})
import { wasm } from 'rolldown-plugin-wasm'
import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['src/index.ts'],
plugins: [wasm()],
})
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
target: 'chrome100',
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "src/styles/variables" as *;`,
},
},
},
})
export default defineConfig({
entry: ['src/cli.ts'],
exe: true,
})
@tsdown/exe)export default defineConfig({
entry: ['src/cli.ts'],
exe: {
targets: [
{ platform: 'linux', arch: 'x64', nodeVersion: '25.7.0' },
{ platform: 'darwin', arch: 'arm64', nodeVersion: '25.7.0' },
{ platform: 'win', arch: 'x64', nodeVersion: '25.7.0' },
],
},
})
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
hooks: {
'build:before': async (context) => {
console.log('Building...')
},
'build:done': async (context) => {
console.log('Build complete!')
},
},
})
Export an array for multiple build configurations:
export default defineConfig([
{
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
},
{
entry: ['src/cli.ts'],
format: ['esm'],
platform: 'node',
},
])
Use functions for dynamic configuration:
export default defineConfig((options) => {
const isDev = options.watch
return {
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
minify: !isDev,
sourcemap: isDev,
}
})
Use glob patterns to build multiple packages:
export default defineConfig({
workspace: 'packages/*',
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
})
# Basic commands
tsdown # Build once
tsdown --watch # Watch mode
tsdown --config custom.ts # Custom config
npx tsdown-migrate # Migrate from tsup
# Output options
tsdown --format esm,cjs # Multiple formats
tsdown -d lib # Custom output directory (--out-dir)
tsdown --minify # Enable minification
tsdown --dts # Generate declarations
tsdown --exe # Bundle as standalone executable
tsdown --unbundle # Bundleless mode
# Entry options
tsdown src/index.ts # Single entry
tsdown src/*.ts # Glob patterns
tsdown src/a.ts src/b.ts # Multiple entries
# Workspace / Monorepo
tsdown -W # Enable workspace mode
tsdown -W -F my-package # Filter specific package
tsdown --filter /^pkg-/ # Filter by regex
# Development
tsdown --watch # Watch mode
tsdown --sourcemap # Generate source maps
tsdown --clean # Clean output directory
tsdown --from-vite # Reuse Vite config
tsdown --tsconfig tsconfig.build.json # Custom tsconfig
Always generate type declarations for TypeScript libraries:
{ dts: true }
Externalize dependencies to avoid bundling unnecessary code:
{ deps: { neverBundle: [/^react/, /^@myorg\//] } }
Use tree shaking for optimal bundle size:
{ treeshake: true }
Enable minification for production builds:
{ minify: true }
Add shims for better ESM/CJS compatibility:
{ shims: true } // Adds __dirname, __filename, etc.
Auto-generate package.json exports :
{ exports: true } // Creates proper exports field
Weekly Installs
430
Repository
GitHub Stars
3.7K
First Seen
Jan 29, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex387
opencode383
github-copilot382
gemini-cli374
amp358
kimi-cli355
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
103,800 周安装
策略对比脚本 - 多策略回测分析与可视化工具,优化交易决策
416 周安装
Spring Boot 3.x OpenAPI 文档生成指南 - SpringDoc集成与Swagger UI配置
416 周安装
React Native 移动端 UI 设计规范与无障碍开发指南 | 最佳实践
417 周安装
CRM自动化工作流:HubSpot/Salesforce/Pipedrive潜在客户管理、交易跟踪与多CRM同步
417 周安装
敏捷产品负责人工具包 - 自动生成用户故事、冲刺规划与优先级排序
417 周安装
42个AI营销技能套件:SEO优化、内容创作、增长黑客与自动化工具
417 周安装
dts: true, dts: { sourcemap, compilerOptions, vue } |
| option-dts |
| Target environment | target: 'es2020', target: 'esnext' | option-target |
| Platform | platform: 'node', platform: 'browser' | option-platform |
| Tree shaking | treeshake: true, custom options | option-tree-shaking |
| Minification | minify: true, minify: 'dce-only' | option-minification |
| Source maps | sourcemap: true, 'inline', 'hidden' | option-sourcemap |
| Watch mode | watch: true, watch options | option-watch-mode |
| Cleaning | clean: true, clean patterns | option-cleaning |
| Log level | logLevel: 'silent', failOnWarn: false | option-log-level |
| option-dependencies |
| Auto external | Automatic dependency/peer/optional externalization | option-dependencies |
css: { ... }@tsdown/css| option-css |
| CSS modules | css: { modules: { localsConvention: 'camelCase' } } — scoped class names for .module.css files | option-css |
| CSS inject | css: { inject: true } — preserve CSS imports in JS output | option-css |
| Unbundle mode | unbundle: true - Preserve directory structure | option-unbundle |
| Root directory | root: 'src' - Control output directory mapping | option-root |
| Executable | [experimental] exe: true - Bundle as standalone executable, cross-platform via @tsdown/exe | option-exe |
| Package validation | publint: true, attw: true - Validate package | option-lint |
Use watch mode during development:
tsdown --watch
Preserve structure for utilities with many files:
{ unbundle: true } // Keep directory structure
Validate packages in CI before publishing:
{ publint: 'ci-only', attw: 'ci-only' }