# CLI Reference Complete reference for tsdown command-line interface. ## Overview All CLI flags can also be set in the config file. CLI flags override config file options. ## Flag Patterns CLI flag mapping rules: - `--foo` sets `foo: true` - `--no-foo` sets `foo: false` - `--foo.bar` sets `foo: { bar: true }` - `--format esm --format cjs` sets `format: ['esm', 'cjs']` CLI flags support both camelCase and kebab-case. For example, `--outDir` and `--out-dir` are equivalent. ## Basic Commands ### Build ```bash # Build with default config tsdown # Build specific files tsdown src/index.ts src/cli.ts # Build with watch mode tsdown --watch ``` ## Configuration ### `--config, -c ` Specify custom config file: ```bash tsdown --config build.config.ts tsdown -c custom-config.js ``` ### `--no-config` Disable config file loading: ```bash tsdown --no-config src/index.ts ``` ### `--config-loader ` Choose config loader (`auto`, `native`, `unrun`): ```bash tsdown --config-loader unrun ``` ### `--tsconfig ` Specify TypeScript config file: ```bash tsdown --tsconfig tsconfig.build.json ``` ## Entry Points ### `[...files]` Specify entry files as arguments: ```bash tsdown src/index.ts src/utils.ts ``` ## Output Options ### `--format ` Output format (`esm`, `cjs`, `iife`, `umd`): ```bash tsdown --format esm tsdown --format esm --format cjs ``` ### `--out-dir, -d ` Output directory: ```bash tsdown --out-dir lib tsdown -d dist ``` ### `--dts` Generate TypeScript declarations: ```bash tsdown --dts ``` ### `--clean` Clean output directory before build: ```bash tsdown --clean ``` ## Build Options ### `--target ` JavaScript target version: ```bash tsdown --target es2020 tsdown --target node18 tsdown --target chrome100 tsdown --no-target # Disable transformations ``` ### `--platform ` Target platform (`node`, `browser`, `neutral`): ```bash tsdown --platform node tsdown --platform browser ``` ### `--minify` Enable minification: ```bash tsdown --minify tsdown --no-minify ``` ### `--sourcemap` Generate source maps: ```bash tsdown --sourcemap tsdown --sourcemap inline ``` ### `--treeshake` Enable/disable tree shaking: ```bash tsdown --treeshake tsdown --no-treeshake ``` ## Dependencies ### `--external ` Mark module as external (not bundled): ```bash tsdown --external react --external react-dom ``` ### `--shims` Add ESM/CJS compatibility shims: ```bash tsdown --shims ``` ## Development ### `--watch, -w [path]` Enable watch mode: ```bash tsdown --watch tsdown -w tsdown --watch src # Watch specific directory ``` ### `--ignore-watch ` Ignore paths in watch mode: ```bash tsdown --watch --ignore-watch test ``` ### `--on-success ` Run command after successful build: ```bash tsdown --watch --on-success "echo Build complete!" ``` ## Environment Variables ### `--env.* ` Set compile-time environment variables: ```bash tsdown --env.NODE_ENV=production --env.API_URL=https://api.example.com ``` Access as `import.meta.env.*` or `process.env.*`. ### `--env-file ` Load environment variables from file: ```bash tsdown --env-file .env.production ``` ### `--env-prefix ` Filter environment variables by prefix (default: `TSDOWN_`): ```bash tsdown --env-file .env --env-prefix APP_ --env-prefix TSDOWN_ ``` ## Assets ### `--copy ` Copy directory to output: ```bash tsdown --copy public tsdown --copy assets --copy static ``` ## Package Management ### `--exports` Auto-generate package.json exports field: ```bash tsdown --exports ``` ### `--publint` Enable package validation: ```bash tsdown --publint ``` ### `--attw` Enable "Are the types wrong" validation: ```bash tsdown --attw ``` ### `--unused` Check for unused dependencies: ```bash tsdown --unused ``` ## Logging ### `--log-level ` Set logging verbosity (`silent`, `error`, `warn`, `info`): ```bash tsdown --log-level error tsdown --log-level warn ``` ### `--report` / `--no-report` Enable/disable build report: ```bash tsdown --no-report # Disable size report tsdown --report # Enable (default) ``` ### `--debug [feat]` Show debug logs: ```bash tsdown --debug tsdown --debug rolldown # Debug specific feature ``` ## Integration ### `--from-vite [vitest]` Extend Vite or Vitest config: ```bash tsdown --from-vite # Use vite.config.* tsdown --from-vite vitest # Use vitest.config.* ``` ## Common Usage Patterns ### Basic Build ```bash tsdown ``` ### Library (ESM + CJS + Types) ```bash tsdown --format esm --format cjs --dts --clean ``` ### Production Build ```bash tsdown --minify --clean --no-report ``` ### Development (Watch) ```bash tsdown --watch --sourcemap ``` ### Browser Bundle (IIFE) ```bash tsdown --format iife --platform browser --minify ``` ### Node.js CLI Tool ```bash tsdown --format esm --platform node --shims ``` ### Monorepo Package ```bash tsdown --clean --dts --exports --publint ``` ### With Environment Variables ```bash tsdown --env-file .env.production --env.BUILD_TIME=$(date +%s) ``` ### Copy Assets ```bash tsdown --copy public --copy assets --clean ``` ## Tips 1. **Use config file** for complex setups 2. **CLI flags override** config file options 3. **Chain multiple formats** for multi-target builds 4. **Use --clean** to avoid stale files 5. **Enable --dts** for TypeScript libraries 6. **Use --watch** during development 7. **Add --on-success** for post-build tasks 8. **Use --exports** to auto-generate package.json fields ## Related Documentation - [Config File](option-config-file.md) - Configuration file options - [Entry](option-entry.md) - Entry point configuration - [Output Format](option-output-format.md) - Format options - [Watch Mode](option-watch-mode.md) - Watch mode details