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

esm support #44

Open
antony opened this issue Apr 4, 2021 · 4 comments · May be fixed by #48
Open

esm support #44

antony opened this issue Apr 4, 2021 · 4 comments · May be fixed by #48

Comments

@antony
Copy link

antony commented Apr 4, 2021

I use this module in a number of client-side libraries, and with Svelte-Kit, which uses Vite under the hood.

Because Vite/Svelte-Kit are esm-first, configuration needs to be added to any apps which use my libraries.

How would you feel about a PR to add a small (5-7 line or so) rollup config which would build an esm-compatible version of this library and export it as the module attribute from package.json?

Or, alternative solutions welcome.

@mcollina
Copy link
Owner

mcollina commented Apr 5, 2021

Could you please create a small repo or gist to describe your use case fully? I'm still learning Vite.

Note that this module has a dependency, reusify, so I guess we would do the same there as well? How would that work?

@antony
Copy link
Author

antony commented Apr 6, 2021

Yes will do!

When you bundle the code for esm distribution, it will rewrite the dependencies, and their dependencies, and so on, all the way down the stack, so you just need to tell it what the entrypoint is, and it'll do the rest, which means reusify will be fine.

@benmccann
Copy link

Depending on how much you want to jump on the ESM train there are at least a few ways to handle this:

  • add a build step that takes the current CJS source and distributes both it and an ESM version
  • convert the source to ESM and add a build step that takes the ESM source and distributes both it and a CJS version
  • convert the source to ESM. Will only work on currently supported version of Node and no EOL versions. Would require one of these options to be undertaken in reusify as well

@mcollina
Copy link
Owner

Converting to ESM only is not viable. I think the only viable path is bundling and providing a module entry point.

@antony antony linked a pull request May 28, 2021 that will close this issue
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 a pull request may close this issue.

3 participants