huozhi / bunchee

Zero config bundler for ECMAScript and TypeScript packages
https://npmjs.com/bunchee
861 stars 28 forks source link

Tree shaking / code splitting #488

Open lovrozagar opened 3 months ago

lovrozagar commented 3 months ago

I am building a component library for Next.js, using bunchee to compile but when using only one component out of many in the consumer app, my whole library is included in the built app bundle size. Looking at the build file that bunchee generates for the component library, code is split into many smaller files, I am using "use client" directive somewhere and those components are separate files too.

Maybe I am missing something. It would be good to note what is needed for tree shaking in the docs as I am unable to find more info on this topic.

Code_rqXRvvjZXk

huozhi commented 3 months ago

Can you share a reproduction with both library and your next.js code? It has few factors that could effect the tree-shaking

lovrozagar commented 1 month ago

Sorry for the late reply.

Sure here is the library repo: https://github.com/lovrozagar/renderui-core/blob/main/package.json

and nextjs starter with one import to showcase the issue: https://github.com/lovrozagar/bunchee-treshake-reproduction