How to specify entrypoints of all files into root dist in tsup/typescript?

439 Views Asked by At

I am using TypeScript with tsup build tool for typescript bundling. I need to specify all folders and files inside components folder to root dist.

src/
   components/
        card/
            card.tsx
            index.ts
        carousel/
            carousel.tsx
            index.ts

        ...other components...
  
   index.ts   

The current output dir I get is like this:

dist/
    components
        card
            card.d.ts
            card.js
            index.d.ts
            index.js
        carousel
            carousel.d.ts
            carousel.js
            index.d.ts
            index.js
        ...

But for more convenience when importing (tree-shaking), I want to put all my components inside the components folder into dist like this:

dist/
    card
       card.d.ts
       card.js
       index.d.ts
       index.js
    carousel
       carousel.d.ts
       carousel.js
       index.d.ts
       index.js
    ...

Here is my tsup config file:

export default defineConfig((options: Options) => ({
   treeshake: true,
   splitting: true,
   entry: ['src/**/*.{ts,tsx}'],
   format: ['cjs', 'esm'],
   dts: true,
   ...options,
}));
0

There are 0 best solutions below