Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow specifying extension of declaration files #292

Closed
wants to merge 8 commits into from
Closed

feat: Allow specifying extension of declaration files #292

wants to merge 8 commits into from

Conversation

lachlancollins
Copy link

@lachlancollins lachlancollins commented Dec 29, 2023

Fixes #267

This allows you to replace the .d.ts extension with one of your liking (e.g. .d.cts, .d.mts) by passing in the dtsExtension option.

If not set, it does nothing. If set, it changes where declarations and declaration maps get written, updates the "file" field in the declaration map, and updates the sourceMappingURL field in the declaration.

I found it was incompatible with rollupTypes: true, so it will not run if it finds this is enabled. Making that compatible would require a more extensive refactor.

This solves needing to use an afterBuild function to rename file extensions.

lachlancollins added a commit to TanStack/config that referenced this pull request Jan 3, 2024
* feat: Add vite build config export

* Fix exports

* Add declaration

* Fix prettier

* Add react integration

* Add CJS test

* Add documentation

* Update deps

* Update tsconfig.json and docs

* Remove duplicated deps

* Update docs

* Add more src files to react integration

* Add vue integration

* Add vue snapshot

* Disable declarationMap until dtsExtension added to vite-plugin-dts

See: qmhc/vite-plugin-dts#292

* Update integration snapshots

* docs: Update vite instructions
@lachlancollins
Copy link
Author

lachlancollins commented Jan 28, 2024

I'm closing this because I found a workaround using beforeWriteFile:

        beforeWriteFile: (filePath, content) => {
          filePath = filePath.replace('.d.ts', '.d.cts')
          return { filePath, content }
        },

I don't think it will work with declaration maps, but it's a reasonable solution for my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate different declaration types
1 participant