Treeshaking (import on demand) for component library #14676
bilalbhojani24
started this conversation in
General
Replies: 1 comment 4 replies
-
If I am understanding correctly, for that you'll need to pass each component as an entry point to Take a look at this blog (coincidentally which I checked today, fun). also do check out the comments on the blog for some drawbacks wrt usage in nextjs Warning You should mark as |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am working on creating a react component library using Vite and rollup as a module bundler.
Problem:- I have 50 components in the library(design-system) and many 3rd party packages and the size of my library is 3MB where my code is 0.8MB and 2.2MB is vendor code. I am bundling everything in a single file, so my library is getting used by another library/app even if 1 component is used from my package whole package size includes the size of design-system.
Analysis:- My code of 50 components is getting treeshaked, but vendor code is minified and not getting treeshaked.
Expected Behavior:-
I am trying to achieve to create a separate file for each component so that the file should contain all needed packages and minified code. Something like import on demand so whenever that component gets rendered, that file should be loaded on go like antd or mui does.
What I have tried?
Current vite config of design-system library:-
Beta Was this translation helpful? Give feedback.
All reactions