qmhc / vite-plugin-dts

A Vite plugin for generating `.d.ts` files.
MIT License
1.31k stars 91 forks source link

Merge all d.ts files into a single d.ts file? #55

Closed moritzmla closed 2 years ago

moritzmla commented 2 years ago

Is it possible to merge all d.ts files into a single d.ts file?

qmhc commented 2 years ago

I recommend you using @microsoft/api-extractor to merge d.ts files into a single file, it's well at this work so that I don't want to make duplicate.

The @microsoft/api-extractor cannot resolve dynamic imports, you can use staticImport: true of this plugin's options to transfrom dynamic to static.

cdauth commented 2 years ago

I would also really love to have this feature. Vite outputs a single .js bundle, so it would be really nice if we could get it to bundle a single .d.ts bundle along with it.

API Extractor looks rather complicated to use, and it's also not clear to me how to embed it into the build process in such a way that only a single .d.ts file ends up in the dist folder. Wouldn't it be an option to make this plugin use API Extractor to output a single bundle?

luckylooke commented 1 year ago

As far as I understand from API Extractor docs, it can't be used as it needs single *.d.ts as entrypoint and output of vite-plugin-dts does not contain such entry point. Same limit has most of the dts bundlers. I found only one which did not required dts entry point, but it takes tsconfig.json so it does not understand vue 😭

I didn’t find any working solution so far. 😢

eightHundreds commented 1 year ago

use rollup + rollup-plugin-dts , but there will be problems when it is used with vite.

lisonge commented 1 year ago

it work for me

pnpm exec tsup .\src\index.ts --dts-only
rxliuli commented 1 year ago

Eventually, I wrote my own code to achieve

https://github.com/rxliuli/liuli-tools/blob/e61812c10e2ca213cdb472c4abf0d08ed190f17f/packages/vite-plugin-node/src/plugins/dts.ts#L7

smastrom commented 1 year ago

This is the config I use to get a single index.d.ts will all declarations merged:

plugins: [
   dts({
      include: ['src'],
      staticImport: true,
      insertTypesEntry: true,
      rollupTypes: true,
   }),
],