Are you an LLM? You can read better optimized documentation at /options/root.md for this page in Markdown format
Root Directory
The root option specifies the root directory of your input files, similar to TypeScript's rootDir. It determines how the output directory structure is computed from your entry files.
Default Behavior
By default, root is automatically computed as the common base directory of all entry files. For example, if your entries are src/a.ts and src/b.ts, the root will be src/.
How to Configure
ts
import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['src/index.ts', 'src/utils/helper.ts'],
root: 'src',
})Or via CLI:
bash
tsdown --root srcHow It Works
The root option affects two behaviors:
- Entry name resolution: When using array entries, file paths relative to
rootdetermine the output filenames. - Unbundle mode: In unbundle mode,
rootis used as thepreserveModulesRoot, controlling the output directory structure.
Example
Given the following project structure:
project/
src/
index.ts
utils/
helper.tsWithout root (default behavior)
ts
export default defineConfig({
entry: ['src/index.ts', 'src/utils/helper.ts'],
})The common base directory is src/, so the output will be:
dist/
index.js
utils/
helper.jsWith explicit root
ts
export default defineConfig({
entry: ['src/index.ts', 'src/utils/helper.ts'],
root: '.',
})Now the root is the project directory, so the output preserves the src/ prefix:
dist/
src/
index.js
utils/
helper.jsWhen to Use
- When the auto-computed common base directory doesn't produce the desired output structure.
- When you want output paths to include or exclude certain directory prefixes.
- When using unbundle mode and need fine-grained control over the output directory mapping.