Library mode: How should I manage external dependencies? #6198
-
Let's say I'm building a library with a few dependencies: react, moment, lodash, and uuid, and I want to distribute this in both ES and UMD format. I'm also wary of the final bundle size of the user's application. React should go into In my mind, the library should avoid including any external dependencies, since these risk being duplicated by the library user's application if they were to use the same dependencies. Thus, I imagine my
package.json should contain all dependencies listed in externals as The main con I see with this is that anybody using UMD bundles would need to include additional script tags with all dependencies from other sources, e.g: Do you agree with this approach, or do you recommend something else? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
I tried using
|
Beta Was this translation helpful? Give feedback.
-
@jimmycallin what approach did you end up using here? I'm running into the same problem, and I'd love to know what's recommended. |
Beta Was this translation helpful? Give feedback.
-
I saw this somewhere else Import Package
And then external exclude these
|
Beta Was this translation helpful? Give feedback.
I appreciate you following up. I actually ended up making a Vite plugin for this since I ran into it for multiple projects now. https://github.com/davidmyersdev/vite-plugin-externalize-deps