Subchapter 8.7
references/guide-getting-started.mdMarkdown3 KBView on GitHub
Install tsdown as a development dependency:
pnpm add -D tsdown
# Optionally install TypeScript if not using isolatedDeclarations
pnpm add -D typescriptRequirements:
[!NOTE] The Node.js 22.18+ requirement only applies to the environment that runs
tsdownitself. The bundled output can target much lower Node.js versions via thetargetoption, so libraries built with tsdown are not locked to Node.js 22+ at runtime.If your package needs to support Node.js 18 / 20, the recommended workflow is to build with Node.js 22+ in CI, then test the built output (or the packed tarball) against the lower Node.js versions you intend to support.
Use create-tsdown CLI for instant setup:
pnpm create tsdown@latestProvides templates for:
// src/index.ts
import { hello } from './hello.ts'
hello()
// src/hello.ts
export function hello() {
console.log('Hello tsdown!')
}// tsdown.config.ts
import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['./src/index.ts'],
})./node_modules/.bin/tsdownOutput: dist/index.mjs
node dist/index.mjs
# Output: Hello tsdown!{
"scripts": {
"build": "tsdown"
}
}Run with:
pnpm build# Check version
tsdown --version
# View help
tsdown --help
# Build with watch mode
tsdown --watch
# Build with specific format
tsdown --format esm,cjs
# Generate type declarations
tsdown --dtsexport default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
clean: true,
})export default defineConfig({
entry: ['src/index.ts'],
format: ['iife'],
globalName: 'MyLib',
platform: 'browser',
minify: true,
})export default defineConfig({
entry: {
index: 'src/index.ts',
utils: 'src/utils.ts',
cli: 'src/cli.ts',
},
format: ['esm', 'cjs'],
dts: true,
})Add Rolldown, Rollup, or Unplugin plugins:
import SomePlugin from 'some-plugin'
export default defineConfig({
entry: ['src/index.ts'],
plugins: [SomePlugin()],
})Enable automatic rebuilds on file changes:
tsdown --watch
# or
tsdown -w