Skip to content
This repository has been archived by the owner on Jul 12, 2021. It is now read-only.

[Feature] Distribute ESM bundle #6

Closed
IanVS opened this issue Jun 3, 2021 · 5 comments · Fixed by #8
Closed

[Feature] Distribute ESM bundle #6

IanVS opened this issue Jun 3, 2021 · 5 comments · Fixed by #8
Labels
bug Something isn't working

Comments

@IanVS
Copy link
Member

IanVS commented Jun 3, 2021

Describe the bug

This addon is not compatible with the vite builder, because it does not expose es modules.

Steps to reproduce the behavior

Use addon-essentials with https://github.com/eirslett/storybook-builder-vite, and observe the error message in the console

Expected behavior

I expect this to work correctly with modern storybook builders like vite.

@IanVS IanVS added the bug Something isn't working label Jun 3, 2021
@IanVS
Copy link
Member Author

IanVS commented Jun 3, 2021

I don't have a ton of experience in that area. However, node has supported es modules since version 12, which is the oldest LTS version right now (10 was end-of-life about a month ago). So, is there a reason not to only distribute es modules? I guess to maintain support for IE11, if that's something you still need. I'm really excited for the day everyone can stop worrying about IE11, hopefully it's soon.

If you want to distribute both, I think the best way is either with a wrapper or conditional exports. The approaches are laid out pretty well in https://nodejs.org/api/packages.html#packages_dual_commonjs_es_module_packages. I have been trying to find examples of how other packages do it, without any luck so far, but I'll post back if I do. If we figure out a good way to do this, we should probably update the addon-kit.

@IanVS
Copy link
Member Author

IanVS commented Jun 3, 2021

It looks like storybook itself uses the "module" field, which is a non-standard field for webpack. It would be nice to avoid that, but this PR might give some good hints on how to set up multiple build targets: storybookjs/storybook#13013

@winkerVSbecks
Copy link
Collaborator

Yea, I spoke to Norbert about this. I'll add in the ESM support today/tomorrow. Will share a preview release for you to test out.

@IanVS
Copy link
Member Author

IanVS commented Jun 3, 2021

From discord it sounds like a change to addon-kit to double-publish should be landing tomorrow. 🎉 So maybe it's worth holding off until we see what shape that takes?

@winkerVSbecks
Copy link
Collaborator

@IanVS could you test this out with 1.2.1--canary.1d6561e.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants