Subchapter 8.38
references/reference-cli.mdMarkdown7 KBView on GitHub
All CLI flags can also be set in the config file. CLI flags override config file options.
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.
# Build with default config
tsdown
# Build specific files
tsdown src/index.ts src/cli.ts
# Build with watch mode
tsdown --watchSpecify custom config file:
tsdown --config build.config.ts
tsdown -c custom-config.jsDisable config file loading:
tsdown --no-config src/index.tsChoose config loader (auto, native, unrun):
tsdown --config-loader unrunSpecify TypeScript config file:
tsdown --tsconfig tsconfig.build.jsonSpecify entry files as arguments:
tsdown src/index.ts src/utils.tsOutput format (esm, cjs, iife, umd):
tsdown --format esm
tsdown --format esm --format cjsOutput directory:
tsdown --out-dir lib
tsdown -d distGenerate TypeScript declarations:
tsdown --dtsClean output directory before build:
tsdown --cleanJavaScript target version:
tsdown --target es2020
tsdown --target node18
tsdown --target chrome100
tsdown --no-target # Disable transformationsTarget platform (node, browser, neutral):
tsdown --platform node
tsdown --platform browserEnable minification:
tsdown --minify
tsdown --no-minifyGenerate source maps:
tsdown --sourcemap
tsdown --sourcemap inlineEnable/disable tree shaking:
tsdown --treeshake
tsdown --no-treeshakeMark module as external (not bundled):
tsdown --deps.never-bundle react --deps.never-bundle react-domSkip resolving and bundling all node_modules:
tsdown --deps.skip-node-modules-bundleAdd ESM/CJS compatibility shims:
tsdown --shimsEnable watch mode:
tsdown --watch
tsdown -w
tsdown --watch src # Watch specific directoryIgnore paths in watch mode:
tsdown --watch --ignore-watch testRun command after successful build:
tsdown --watch --on-success "echo Build complete!"Set compile-time environment variables:
tsdown --env.NODE_ENV=production --env.API_URL=https://api.example.comAccess as import.meta.env.* or process.env.*.
Load environment variables from file:
tsdown --env-file .env.productionFilter environment variables by prefix (default: TSDOWN_):
tsdown --env-file .env --env-prefix APP_ --env-prefix TSDOWN_Copy directory to output:
tsdown --copy public
tsdown --copy assets --copy static[experimental] Bundle as a standalone executable using Node.js Single Executable Applications (opens in a new tab). Requires Node.js >= 25.5.0, not supported in Bun or Deno. Cross-platform builds supported via @tsdown/exe.
tsdown --exeWhen enabled:
cjs (unless Node.js >= 25.7.0)dts) is disabled by defaultSee Executable for advanced configuration and cross-platform builds.
Generate the exports field in package.json:
tsdown --exportsEnable package validation:
tsdown --publintEnable “Are the types wrong” validation:
tsdown --attwCheck for unused dependencies:
tsdown --unusedSet logging verbosity (silent, error, warn, info):
tsdown --log-level error
tsdown --log-level warnEnable/disable build report:
tsdown --no-report # Disable size report
tsdown --report # Enable (default)Show debug logs:
tsdown --debug
tsdown --debug rolldown # Debug specific featureExtend Vite or Vitest config:
tsdown --from-vite # Use vite.config.*
tsdown --from-vite vitest # Use vitest.config.*Enable workspace mode for building multiple packages:
tsdown -W
tsdown -W packages/Filter configs by name or working directory. Supports regex:
tsdown -W -F my-package
tsdown -W -F /^pkg-/Enable unbundle (bundleless) mode:
tsdown --unbundleSpecify the root directory of input files (similar to TypeScript’s rootDir). Controls the output directory structure by determining how entry file paths map to output paths. Defaults to the common base directory of all entry files.
tsdown --root src
tsdown --root .Fail on warnings (enabled by default):
tsdown --no-fail-on-warn # Disabletsdowntsdown --format esm --format cjs --dts --cleantsdown --minify --clean --no-reporttsdown --watch --sourcemaptsdown --format iife --platform browser --minifytsdown --format esm --platform node --shimstsdown src/cli.ts --exetsdown --clean --dts --exports --publinttsdown --env-file .env.production --env.BUILD_TIME=$(date +%s)tsdown --copy public --copy assets --cleanThis file