tsdown-migrate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMigrating from tsup to tsdown
从tsup迁移至tsdown
Knowledge base for AI agents to migrate tsup projects to tsdown — the Rolldown-powered library bundler.
供AI Agent使用的知识库,用于将tsup项目迁移至tsdown——基于Rolldown的库打包工具。
When to Use
适用场景
- Migrating a project from tsup to tsdown
- Understanding differences between tsup and tsdown options
- Reviewing or fixing post-migration configuration issues
- Advising users on tsup→tsdown compatibility
- 将项目从tsup迁移至tsdown
- 了解tsup与tsdown的选项差异
- 排查或修复迁移后的配置问题
- 为用户提供tsup→tsdown兼容性建议
Migration Overview
迁移概述
Follow these steps to migrate a tsup project:
- Rename config file: →
tsup.config.*tsdown.config.* - Update imports: →
'tsup''tsdown' - Apply option mappings: Rename/transform options per tables below
- Preserve tsup defaults: Explicitly set options that differ (format, clean, dts, target)
- Update package.json: Dependencies, scripts, root config field
- Remove unsupported options: Replace with alternatives where available
- Test build: Run and verify output
tsdown
按照以下步骤迁移tsup项目:
- 重命名配置文件:→
tsup.config.*tsdown.config.* - 更新导入语句:→
'tsup''tsdown' - 应用选项映射:根据下方表格重命名/转换选项
- 保留tsup默认值:显式设置存在差异的选项(format、clean、dts、target)
- 更新package.json:依赖项、脚本、根配置字段
- 移除不支持的选项:如有可用方案则替换为替代选项
- 测试构建:运行并验证输出结果
tsdown
Config File Migration
配置文件迁移
File Rename
文件重命名
| tsup | tsdown |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| tsup | tsdown |
|---|---|
| |
| |
| |
| |
| |
| |
| |
Import and Identifier Changes
导入与标识符变更
ts
// Before
import { defineConfig } from 'tsup'
// After
import { defineConfig } from 'tsdown'Replace all identifiers: → , → .
tsuptsdownTSUPTSDOWNts
// 迁移前
import { defineConfig } from 'tsup'
// 迁移后
import { defineConfig } from 'tsdown'替换所有标识符: → , → 。
tsuptsdownTSUPTSDOWNOption Mappings
选项映射
Property Renames
属性重命名
| tsup | tsdown | Notes |
|---|---|---|
| | CJS default export handling |
| | Now uses Rolldown/Unplugin plugins |
| tsup | tsdown | 说明 |
|---|---|---|
| | CJS默认导出处理 |
| | 现在使用Rolldown/Unplugin插件 |
Deprecated but Compatible
已弃用但仍兼容
These tsup options still work in tsdown for backward compatibility, but emit deprecation warnings and will be removed in a future version. Migrate them immediately.
| tsup (deprecated) | tsdown (preferred) | Notes |
|---|---|---|
| | Also deprecated in tsup itself |
| | Copy static files to output |
| (remove) | Bundle is default behavior |
| | Preserve file structure |
| | Strip |
| | CSS injection |
| (remove) | Default behavior |
| | Moved to deps namespace |
| | Moved to deps namespace |
| | Moved to deps namespace |
这些tsup选项在tsdown中仍可使用以实现向后兼容,但会输出弃用警告,且将在未来版本中移除。请立即迁移这些选项。
| tsup(已弃用) | tsdown(推荐) | 说明 |
|---|---|---|
| | tsup自身也已弃用该选项 |
| | 将静态文件复制到输出目录 |
| (移除) | 打包为默认行为 |
| | 保留文件结构 |
| | 移除 |
| | CSS注入 |
| (移除) | 默认行为 |
| | 移至deps命名空间下 |
| | 移至deps命名空间下 |
| | 移至deps命名空间下 |
Dependency Namespace Moves
依赖项命名空间迁移
Dependencies config moved under namespace. If both and exist, merge into a single object:
depsexternalnoExternaldepsts
// Before (tsup)
export default defineConfig({
external: ['react'],
noExternal: ['lodash-es'],
})
// After (tsdown)
export default defineConfig({
deps: {
neverBundle: ['react'],
alwaysBundle: ['lodash-es'],
},
})tsdown also adds (whitelist of allowed bundled packages) — no tsup equivalent.
deps.onlyBundle依赖项配置已移至命名空间下。如果同时存在和,请合并为单个对象:
depsexternalnoExternaldepsts
// 迁移前(tsup)
export default defineConfig({
external: ['react'],
noExternal: ['lodash-es'],
})
// 迁移后(tsdown)
export default defineConfig({
deps: {
neverBundle: ['react'],
alwaysBundle: ['lodash-es'],
},
})tsdown还新增了(允许打包的包白名单)——tsup无对应功能。
deps.onlyBundlePlugin Import Transforms
插件导入转换
ts
// Before (tsup - esbuild plugins)
import plugin from 'unplugin-example/esbuild'
// After (tsdown - Rolldown plugins)
import plugin from 'unplugin-example/rolldown'All imports should change to .
unplugin-*/esbuildunplugin-*/rolldownFor complete before/after examples of every transformation, see guide-option-mappings.md.
ts
// 迁移前(tsup - esbuild插件)
import plugin from 'unplugin-example/esbuild'
// 迁移后(tsdown - Rolldown插件)
import plugin from 'unplugin-example/rolldown'所有导入应改为。
unplugin-*/esbuildunplugin-*/rolldown如需查看所有转换的完整前后示例,请参阅guide-option-mappings.md。
Default Value Differences
默认值差异
tsdown changes several defaults from tsup. When migrating, explicitly set these to preserve tsup behavior, then let the user decide which new defaults to adopt.
| Option | tsup Default | tsdown Default | Migration Action |
|---|---|---|---|
| | | Set |
| | | Set |
| | Auto-enabled if | Set |
| (none) | Auto-reads from | Set |
After migration, suggest the user review these — tsdown's defaults are generally better:
- ESM is the modern standard
- Cleaning output prevents stale files
- Auto DTS from package.json reduces config
- Auto target from engines.node ensures consistency
tsdown修改了tsup的多个默认值。迁移时,请显式设置这些选项以保留tsup的行为,之后再由用户决定是否采用新默认值。
| 选项 | tsup默认值 | tsdown默认值 | 迁移操作 |
|---|---|---|---|
| | | 设置 |
| | | 设置 |
| | 若package.json中存在 | 设置 |
| (无) | 从package.json的 | 设置 |
迁移完成后,建议用户评估这些选项——tsdown的默认值通常更优:
- ESM是现代标准
- 清理输出目录可避免残留文件
- 从package.json自动生成DTS可减少配置
- 从engines.node自动读取target可确保一致性
Unsupported Options
不支持的选项
These tsup options have no direct equivalent in tsdown. Remove them and inform the user.
| tsup Option | Status | Alternative |
|---|---|---|
| Always enabled | Remove — code splitting cannot be disabled in tsdown |
| Not available | Suggest |
| Not supported | Remove — tsdown uses oxc for transformation (built-in) |
| Not supported | Use the |
| Not supported | Remove — no alternative |
| Incompatible | Migrate to Rolldown plugins manually; tsup's plugin API differs from Rolldown's |
这些tsup选项在tsdown中无直接等效功能。请移除它们并告知用户。
| tsup选项 | 状态 | 替代方案 |
|---|---|---|
| 始终启用 | 移除——tsdown中无法禁用代码分割 |
| 暂不支持 | 建议使用 |
| 不支持 | 移除——tsdown内置使用oxc进行代码转换 |
| 不支持 | 使用 |
| 不支持 | 移除——无替代方案 |
| 不兼容 | 手动迁移至Rolldown插件;tsup的插件API与Rolldown不同 |
Package.json Migration
package.json迁移
Scripts
脚本
Replace and with in all script commands:
tsuptsup-nodetsdownjson
// Before
{
"scripts": {
"build": "tsup src/index.ts",
"dev": "tsup --watch"
}
}
// After
{
"scripts": {
"build": "tsdown src/index.ts",
"dev": "tsdown --watch"
}
}在所有脚本命令中将和替换为:
tsuptsup-nodetsdownjson
// 迁移前
{
"scripts": {
"build": "tsup src/index.ts",
"dev": "tsup --watch"
}
}
// 迁移后
{
"scripts": {
"build": "tsdown src/index.ts",
"dev": "tsdown --watch"
}
}Dependencies
依赖项
| Location | Action |
|---|---|
| Rename to |
| Rename to |
| Rename to |
| Rename to |
| Rename to |
| 位置 | 操作 |
|---|---|
| 重命名为 |
| 重命名为 |
| 重命名为 |
| 重命名为 |
| 重命名为 |
Root Config Field
根配置字段
If package.json has a root-level field (inline config), rename to :
tsuptsdownjson
// Before
{ "tsup": { "entry": ["src/index.ts"] } }
// After
{ "tsdown": { "entry": ["src/index.ts"] } }For detailed package.json examples, see guide-package-json.md.
如果package.json中存在根级别的字段(内联配置),请重命名为:
tsuptsdownjson
// 迁移前
{ "tsup": { "entry": ["src/index.ts"] } }
// 迁移后
{ "tsdown": { "entry": ["src/index.ts"] } }如需查看详细的package.json示例,请参阅guide-package-json.md。
New tsdown Features
tsdown新增功能
After migration, suggest these tsdown-exclusive features to the user:
| Feature | Config | Description |
|---|---|---|
| Node protocol | | Add or strip |
| Workspace | | Build multiple packages in a monorepo |
| Package exports | | Auto-generate |
| Package validation | | Lint package and check type correctness |
| Executable | | Bundle as Node.js standalone executable (SEA) |
| DevTools | | Vite DevTools integration for bundle analysis |
| Hooks | | Lifecycle hooks: |
| CSS modules | | Scoped class names for |
| Glob import | | Support |
For detailed comparisons, see guide-differences-detailed.md.
迁移完成后,可为用户推荐以下tsdown专属功能:
| 功能 | 配置 | 说明 |
|---|---|---|
| Node协议 | | 为内置导入添加或移除 |
| 工作区 | | 在单体仓库中构建多个包 |
| 包导出 | | 自动在package.json中生成 |
| 包验证 | | 检查包的规范与类型正确性 |
| 可执行文件 | | 打包为Node.js独立可执行文件(SEA) |
| 开发工具 | | 集成Vite DevTools用于打包分析 |
| 钩子 | | 生命周期钩子: |
| CSS模块 | | 为 |
| Glob导入 | | 支持 |
如需详细对比,请参阅guide-differences-detailed.md。
References
参考资料
| Topic | Description | Reference |
|---|---|---|
| Option Mappings | Complete before/after for every option transform | guide-option-mappings |
| Detailed Differences | Architecture, features, compatibility comparison | guide-differences-detailed |
| Package.json | Dependency, script, and config field migration | guide-package-json |
| 主题 | 说明 | 参考链接 |
|---|---|---|
| 选项映射 | 所有选项转换的完整前后示例 | guide-option-mappings |
| 详细差异 | 架构、功能、兼容性对比 | guide-differences-detailed |
| package.json迁移 | 依赖项、脚本与配置字段迁移 | guide-package-json |
Migration Checklist
迁移检查清单
Use this checklist when performing a migration:
- [ ] Rename tsup.config.* → tsdown.config.*
- [ ] Update import from 'tsup' to 'tsdown'
- [ ] Replace tsup/TSUP identifiers with tsdown/TSDOWN
- [ ] Apply property renames (cjsInterop→cjsDefault, esbuildPlugins→plugins)
- [ ] Migrate deprecated options (publicDir→copy, bundle→unbundle, removeNodeProtocol→nodeProtocol, injectStyle→css.inject)
- [ ] Move external/noExternal/skipNodeModulesBundle into deps namespace
- [ ] Update unplugin imports from /esbuild to /rolldown
- [ ] Set explicit defaults to preserve tsup behavior (format, clean, dts, target)
- [ ] Remove unsupported options (splitting, metafile, swc, etc.)
- [ ] Update package.json scripts (tsup→tsdown)
- [ ] Update package.json dependencies
- [ ] Rename root-level tsup config field if present
- [ ] Run tsdown and verify build output
- [ ] Suggest new tsdown features to the user执行迁移时可使用以下检查清单:
- [ ] 将tsup.config.*重命名为tsdown.config.*
- [ ] 将导入语句从'tsup'更新为'tsdown'
- [ ] 将tsup/TSUP标识符替换为tsdown/TSDOWN
- [ ] 应用属性重命名(cjsInterop→cjsDefault、esbuildPlugins→plugins)
- [ ] 迁移已弃用选项(publicDir→copy、bundle→unbundle、removeNodeProtocol→nodeProtocol、injectStyle→css.inject)
- [ ] 将external/noExternal/skipNodeModulesBundle移至deps命名空间下
- [ ] 将unplugin导入从/esbuild改为/rolldown
- [ ] 显式设置默认值以保留tsup行为(format、clean、dts、target)
- [ ] 移除不支持的选项(splitting、metafile、swc等)
- [ ] 更新package.json中的脚本(tsup→tsdown)
- [ ] 更新package.json中的依赖项
- [ ] 如有根级tsup配置字段则重命名
- [ ] 运行tsdown并验证构建输出
- [ ] 为用户推荐tsdown新增功能