Skip to content

Added esm bundle to output #9

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

Closed
wants to merge 2 commits into from
Closed

Conversation

shkreios
Copy link
Contributor

Current state

The library only supplies a cjs & d.ts output.

Why change

Even though bundlers, e.g. vite, have support for transforming cjs into esm it's nice when the transformation happens at library level.

Result

This pr adds a esm bundle to the output and updates package.json fields.

"main": "dist/useEvent.js",
"main": "dist/index.js",
"types": "dist/useEvent.d.ts",
"module": "dist/useevent.mjs",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, this sounds like a great addition. Supporting ESM is a good idea.

However, looking at the compiled tsup output, I'm disappointed by the extra complexity. I'm a fan of simply using tsc, and its ESM output is much cleaner and easier to read or debug.

I would love if you could update this PR to simply use tsc, instead of introducing new dependencies.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I was experimenting with this, I created #10

@@ -2,7 +2,9 @@
"name": "react-use-event-hook",
"version": "0.9.2",
"description": "Same as React's `useCallback`, but returns a stable reference.",
"main": "dist/useEvent.js",
"main": "dist/index.js",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outputting to 2 sibling files (eg. useEvent.js, useEvent.mjs) does seem have some problems with some build tools.

There are some solutions listed here: https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html

TL;DR; I think it's best to output to 2 separate folders, eg. dist/cjs/useEvent.js and dist/mjs/useEvent.mjs

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #10

@scottrippey scottrippey mentioned this pull request Feb 22, 2023
@scottrippey scottrippey added the duplicate This issue or pull request already exists label Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants