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

Emitting dts files #4

Closed
cometkim opened this issue Oct 10, 2021 · 8 comments · Fixed by #13
Closed

Emitting dts files #4

cometkim opened this issue Oct 10, 2021 · 8 comments · Fixed by #13
Labels
enhancement New feature or request
Milestone

Comments

@cometkim
Copy link
Owner

questions:

  • Should this do dts bundling? (even there are limitations)
  • If not, is it really necessary?
@cometkim cometkim added enhancement New feature or request question Further information is requested labels Oct 10, 2021
@cometkim
Copy link
Owner Author

@cometkim cometkim removed the question Further information is requested label Dec 10, 2022
@cometkim cometkim modified the milestones: v1.x, v1 Dec 10, 2022
@jrson83
Copy link

jrson83 commented Dec 16, 2022

Any news on this?

@cometkim
Copy link
Owner Author

@jrson83 nanobundle is well emitting dts files as necessary

Do you need something else?

@jrson83
Copy link

jrson83 commented Dec 20, 2022

@cometkim sorry I can't find anything about dts bundling in the docs. Is it possible to bundle .d.ts files with nanobundle like dts-bundle-generator does?

@cometkim
Copy link
Owner Author

I had considered it, but dts-bundling isn't compatible with multiple entries and TypeScript's NodeNext resolution.

Welcome if you have any approach to do it.

@jrson83
Copy link

jrson83 commented Dec 21, 2022

Thanks, I did not know, but I just saw your PR related to tsconfck.

My use-case is a TypeScript module meant for browser and node environment. I have setup a minimal example repo.
If you can take a look would be great.

The file src/index.ts exports src/client.ts and src/router.ts is meant for browser.
The file src/server.ts is meant for node.

When using yarn run build:nanobundle, nanobundle generates the output files with declarations enabled.
It produces multiple d.ts files for the browser bundle (not one bundled d.ts file):

  • lib/client.d.ts
  • lib/index.d.ts
  • (in addition lib/server.d.ts)

As a workaround I tested various settings with dts-bundle-generator. If you run yarn run build:nanobundle:dts, nanobundle generates the output files with declarations disabled, following dts-bundle-generator, generates one d.ts bundle for browser and one d.ts bundle for node. But it takes up to 20 seconds for the command:

  • lib/index.d.ts (lib/client.d.ts is included)
  • (in addition lib/server.d.ts)

I also tested unbuild, as a comparison you can run yarn run build:unbuild, it will also output one bundled lib/index.d.ts and lib/server.d.ts.

Maybe I get this wrong and it's okay how nanobundle bundles the d.ts. I was just wondering, since unbuild bundles the d.ts files, as I expected.

@cometkim
Copy link
Owner Author

It seems to use rollup-plugin-dts. And seems like an ideal option to do dts bundling, but I wouldn't make it the default for several reasons.

  • There is no need to bundle dts (yet)
  • It doesn't support all use case of typescript. Because TypeScript expects files to be split, you can run into unexpected conflicts with merged files.
  • Maybe slow (20 more seconds for build... is way far)

I could experiment with the rollup for dts and introduce it with the --experimental-dts-bundling flag, but it's not a high priority.

@jrson83
Copy link

jrson83 commented Dec 21, 2022

I could experiment with the rollup for dts and introduce it with the --experimental-dts-bundling flag, but it's not a high priority.

That would be great! Thank you.

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

Successfully merging a pull request may close this issue.

2 participants