egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
9.01k stars 217 forks source link

tsup dts doesn't follow source structure #1010

Open sxungchxn opened 1 year ago

sxungchxn commented 1 year ago

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,

image

And the src/index.ts file exports all of them like this

export {
  Badge,
  Button,
} from './components

My expectation of dts is creating separted d.ts files like this.

image

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 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.

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()],
}));

Upvote & Fund

Fund with Polar

pfernandom commented 12 months ago

I think this is intended behavior, otherwise, what would be the difference between what you expect and just running tsc --declaration --emitDeclarationOnly?