1.8 KiB
1.8 KiB
Root Directory
Specify the root directory of input files for output structure mapping.
Overview
The root option is similar to TypeScript's rootDir. It determines how entry file paths map to output paths. By default, tsdown computes the root as the common base directory of all entry files. Setting root explicitly lets you override this behavior.
Basic Usage
CLI
tsdown --root src
Config File
export default defineConfig({
entry: ['src/index.ts', 'src/utils/helper.ts'],
root: 'src',
})
How It Works
Default
Given entries src/index.ts and src/utils/helper.ts, the common base directory is src/:
dist/
├── index.js
└── utils/
└── helper.js
With root: '.'
Setting root to the project directory preserves the src/ prefix:
dist/
└── src/
├── index.js
└── utils/
└── helper.js
What It Affects
- Entry name resolution — Array entry paths are computed relative to
rootfor output filenames - Unbundle mode — Used as
preserveModulesRoot, controlling output structure whenunbundle: true
When to Use
- Auto-computed common base directory doesn't produce desired output structure
- Need to include or exclude directory prefixes in output paths
- Unbundle mode needs specific directory mapping
Common Patterns
Library with src/ Prefix Preserved
export default defineConfig({
entry: ['src/**/*.ts', '!**/*.test.ts'],
root: '.',
unbundle: true,
})
Monorepo Package
export default defineConfig({
entry: ['src/index.ts'],
root: 'src',
unbundle: true,
})
Related Options
- Unbundle - Preserve directory structure
- Entry - Entry point configuration
- Output Directory - Output location