excalidraw / excalidraw

Virtual whiteboard for sketching hand-drawn like diagrams
https://excalidraw.com
MIT License
86.67k stars 8.22k forks source link

Creating ESM build for package @excalidraw/excalidraw #7018

Open ad1992 opened 1 year ago

ad1992 commented 1 year ago

WHY

We currently only support the UMD build for the package which works well for the browser as well as the node. But we also lose the benefits of tree shaking and importing specific utils which aren't possible withumd build.

One recent example is the package @excalidraw/mermaid-to-excalidraw where we wanted to import only a function convertToExcalidrawElements from the package but to do that we will need to add react, react-dom unnecessarily which leads to increase in bundle size as well as taking more bandwidth.

Hence we should support the ESM build, the UMD build will always be there for fallback.

With ESM Build we can support

  1. Importing specific functions as needed without importing the whole bundle
  2. Tree shaking, dead code elimination, and better code splitting as bundlers will have full control over it
  3. In @excalidraw/mermaid-to-excalidraw we can start using convertToExcalidraw function so the host doesn't need to call it explicitly when using the package

HOW

There are a few changes needed in the codebase before we start supporting ESM

With these changes for the ESM build, we will also get closer to Monorepo architecture

RegiByte commented 1 year ago

This is extremely important for the future of this package. I'm willing to help however I can to make this happen. The community would appreciate it a lot!

dwelle commented 1 year ago

Thanks @RegiByte. The effort is underway! We'll post in this issue if there are actionable issues someone could help with.

Do you have experience with publishing ESM packages yourself?

RegiByte commented 1 year ago

@dwelle I have experience publishing ESM and CJS packages, for Excalidraw I don't think CJS will be needed so it's a little easier.

If I can help in any way just let me know, I'm mostly using Excalidraw with rich-text editors like ProseMirror and Lexical, they integrate nicely but the lack of ESM support causes problems with some bundlers depending on how they are configured.

I never contributed to Excalidraw directly but I'd be really happy to if I have the opportunity.

gut4 commented 8 months ago

@ad1992 any updates on this? Looks like all required pull requests were merged

luckyboykg commented 7 months ago

I saw the to-do list was finished. Do you know if we have any updates on this issue?