tsup dts doesn't follow source structure
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 275
- PR merge metrics
- No merged PRs in 30d
Description
While using dts in tsup, there seems to be that all built declaration files are bundled into one file.
What I am expecting that the generated dts structure follows the source structures.
For example, if my source structure looks like this,

And the `src/index.ts` file exports all of them like this
```tsx
export {
Badge,
Button,
} from './components
```
My expectation of dts is creating separted `d.ts` files like this.

However, by applying the dts of tsup, it creates only a single of `.d.ts` file not following above source structure. What I knew that [vite-plugin-dts](https://github.com/qmhc/vite-plugin-dts) is following the source structure like above example.
Is there any way to follow source structure of `dts` in `tsup`?
Or Is this single `d.ts` creation behavior intended for specific reason?
My tsup config that creates a single `d.ts` is as follows.
```ts
import { defineConfig } from 'tsup';
import { TsconfigPathsPlugin } from '@esbuild-plugins/tsconfig-paths';
import { vanillaExtractPlugin } from '@vanilla-extract/esbuild-plugin';
// @ts-expect-error
export default defineConfig((options) => ({
entry: ['src/index.ts'],
outDir: 'dist',
format: ['esm', 'cjs'],
dts: true,
external: ['react', 'react-dom'],
clean: true,
splitting: false,
bundle: true,
minify: !options.watch,
sourcemap: options.watch,
plugins: [
TsconfigPathsPlugin({
tsconfig: './tsconfig.json',
}),
],
esbuildPlugins: [vanillaExtractPlugin()],
}));
```
Contributor guide
Research direction
Reproduce the declaration output from the shown tsup config, beginning at the src/index.ts entry point and its re-exports. Determine whether dts with bundle: true is intended to emit one file or should preserve source structure; done should be a documented, tested behavior matching the chosen output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100