Setting the file. One moment.
Subchapter 8.31
references/option-watch-mode.mdMarkdown5 KBView on GitHub
Watch mode monitors your source files and rebuilds automatically on changes, streamlining the development workflow.
# Watch all project files
tsdown --watch
# Or use short flag
tsdown -w
# Watch specific directory
tsdown --watch ./src
# Watch specific file
tsdown --watch ./src/index.tsexport default defineConfig({
entry: ['src/index.ts'],
watch: true,
})Ignore specific paths in watch mode:
tsdown --watch --ignore-watch test --ignore-watch '**/*.test.ts'export default defineConfig({
entry: ['src/index.ts'],
watch: {
exclude: ['test/**', '**/*.test.ts'],
},
})Run command after successful build:
tsdown --watch --on-success "echo Build complete!"
tsdown --watch --on-success "node dist/index.mjs"export default defineConfig({
entry: ['src/index.ts'],
watch: true,
onSuccess: 'node dist/index.mjs',
})By default, tsdown watches:
During watch mode:
r - Manual rebuildq - Quit watch modeexport default defineConfig((options) => ({
entry: ['src/index.ts'],
format: ['esm'],
watch: options.watch,
sourcemap: options.watch,
minify: !options.watch,
}))export default defineConfig({
entry: ['src/index.ts'],
watch: true,
onSuccess: 'npm run test',
})export default defineConfig({
entry: {
main: 'src/index.ts',
cli: 'src/cli.ts',
},
watch: true,
clean: false, // Don't clean on each rebuild
})# Watch and run tests on change
tsdown --watch --on-success "vitest run"
# Watch and start dev server
tsdown --watch --on-success "node dist/server.mjs"export default defineConfig({
workspace: 'packages/*',
entry: ['src/index.ts'],
watch: true,
watch: {
exclude: ['**/test/**', '**/*.spec.ts'],
},
})export default defineConfig({
entry: ['src/index.ts'],
watch: {
include: ['src/**'],
exclude: ['**/*.test.ts', '**/fixtures/**'],
skipWrite: false,
},
})export default defineConfig((options) => {
const isDev = options.watch
return {
entry: ['src/index.ts'],
format: ['esm'],
dts: !isDev, // Skip DTS in watch mode
sourcemap: isDev,
clean: !isDev,
}
})# Basic watch
tsdown -w
# Watch with source maps
tsdown -w --sourcemap
# Watch without cleaning
tsdown -w --no-clean
# Watch and run on success
tsdown -w --on-success "npm test"
# Watch specific format
tsdown -w --format esm
# Watch with minification
tsdown -w --minify
# Watch and ignore test files
tsdown -w --ignore-watch '**/*.test.ts'exclude patternsAdd ignore patterns:
export default defineConfig({
watch: {
exclude: [
'**/node_modules/**',
'**/.git/**',
'**/dist/**',
'**/*.test.ts',
],
},
})dts: !options.watchminify: falseConfig file changes trigger full restart automatically.
tsdown does not support stub mode. Watch mode is the recommended alternative for rapid development, providing instant rebuilds without the drawbacks of stub mode.