wessberg / rollup-plugin-ts

A TypeScript Rollup plugin that bundles declarations, respects Browserslists, and enables seamless integration with transpilers such as babel and swc
MIT License
496 stars 32 forks source link

Disable cts/mts extensions? #209

Open michaelfaith opened 1 year ago

michaelfaith commented 1 year ago

Question

Is it possible to disable the automatic extension naming? In our package, we're generating both cjs and mjs, but the type declarations are the same, and it would be redundant to include both. We'd like to just have .d.ts files in the root, and the cjs/mjs files nested in a cjs and esm folder. I can't seem to find a way to do this without having two sets of type declarations. This is my only real gripe. Otherwise, I've enjoyed the shift to this library.

RE:

if you're using TypeScript v4.7 or newer, the extension of your declaration files will depend on the extensions of your output files as controlled by your Rollup config:

  • .js output files will produce .d.ts and optionally .d.ts.map files
  • .mjs output files will produce .d.mts and optionally .d.mts.map files
  • .cjs output files will produce .d.cts and optionally .d.cts.map files
liamcmitchell commented 11 months ago

I have used the outputPath hook to rename output files to .d.ts:

  plugins: [
    ts({
      // ...
      hook: {
        outputPath: (path) => path.replace(/\.d\..ts/, '.d.ts'),
      },
    }),

Docs: https://github.com/wessberg/rollup-plugin-ts?tab=readme-ov-file#the-outputpath-hook