Skip to content

参考

版本基线 tsdown 0.22.xlatest,2026-06)。CLI、默认值、tsup 迁移映射、hooks 与版本现状速查。

CLI 速查

bash
npx tsdown                        # 零配置构建(src/index.ts → dist/,ESM)
npx tsdown src/a.ts src/b.ts      # 直接传入口
npx tsdown --format esm --format cjs   # 双格式
npx tsdown --dts                  # 生成声明文件
npx tsdown -w                     # watch 模式(--watch [path])
npx tsdown --ignore-watch tests   # watch 时忽略路径
npx tsdown --minify               # 压缩(Oxc minifier)
npx tsdown --no-treeshake         # 关闭 tree-shaking
npx tsdown --unbundle             # 逐文件输出(镜像源码结构)
npx tsdown --publint --attw       # 发布校验(需自装 publint / @arethetypeswrong/core)
npx tsdown --unused               # 未使用依赖检查
npx tsdown --workspace --filter pkg-a  # monorepo:构建工作区/筛选包
npx tsdown --config ./tsdown.config.ts # 指定配置;--no-config 禁用
npx tsdown-migrate --dry-run      # tsup 迁移(预览)

核心默认值速查

默认值
entrysrc/index.ts(存在时);支持 string/array/object/glob
formatesm(可选 cjs/iife/umd
outDirdist/
扩展名Node 平台固定:ESM .mjs、CJS .cjs;IIFE/UMD 文件名带格式
platformnode(可选 browser/neutralCJS 恒为 node
target自动读 engines.node只转语法不注入 polyfillfalse 全关
cleantrue(构建前清空 outDir)
treeshaketrue
dtspackage.json 含 types/typings 时自动开
依赖deps/peerDeps/optionalDeps 外部化;devDeps 被引用才打入
cjsDefaulttrue:单一 default 导出的 CJS 转 module.exports =(dts 转 export =

tsup → tsdown 迁移映射

tsuptsdown说明
format: 'cjs'(默认)format: 'esm'(默认)默认值差异
clean: false(默认)clean: true(默认)默认值差异
cjsInteropcjsDefault重命名
esbuildPluginsplugins(Rolldown/unplugin)重命名 + 换插件
outExtensionoutExtensions(复数)重命名
entryPointsentry废弃映射,暂可用
publicDircopy废弃映射
bundle: falseunbundle: true废弃映射
injectStyle: truecss: { inject: true }废弃映射
removeNodeProtocol: truenodeProtocol: 'strip'废弃映射
external / noExternaldeps.neverBundle / deps.alwaysBundle废弃映射
skipNodeModulesBundledeps.skipNodeModulesBundle废弃映射
splitting: false——不支持(分割恒开)无对应
metafiledevtools: true无对应,换方案
swc / experimentalDts——(内部用 oxc / 标准 dts无对应
[name].global.js(IIFE)[name].iife.js产物命名差异

unplugin 系插件改导入子路径即可:unplugin-x/esbuildunplugin-x/rolldown

hooks 速查

钩子时机
build:prepare每次 tsdown 构建开始前
build:before每个 Rolldown 构建前(多格式时按格式各触发)
build:done每次构建完成后

注册:配置里 hooks: { 'build:done': fn },或函数式 hooks(h) { h.hook('build:prepare', fn) }(受 unbuild 启发、基于 hookable)。

发布质检三件套

能力开启依赖
publintpublint: true / --publint需自装 publint(可选依赖)
attwattw: true / --attw需自装 @arethetypeswrong/core
未用依赖--unused内置

publint/attw 均支持 'ci-only':本地跳过、CI 强制。

版本现状(2026-06)

dist-tag版本
tsdownlatest0.22.x(0.22.2,未到 1.0)

0.x 阶段 semver 不承诺 minor 兼容:锁版本、升级前读 Releases。运行环境要求 Node.js 22.18.0+。