Next.js Barrel File Tree Shaking Doesn't Work
Unanswered
sirgolem posted this in #help-forum
sirgolemOP
I am building a React component library to use in my apps, and am using a barrel file to clean up long import paths. However, tree shaking doesn't work on the barrel file - if I import a few components from their individual files, my final bundle (production) is around 85kb, but with the barrel file it is 182kb. In development mode the build for one page takes around 9s with 4090 modules.
I have looked at several answers on Stack Overflow and webpack's tree shaking guide, but nothing has worked. I have tried the
What can I do to get tree shaking working properly and reduce my bundle size?
I have looked at several answers on Stack Overflow and webpack's tree shaking guide, but nothing has worked. I have tried the
"sideEffects": false field in my app's package.json, disabling sideEffects through the webpack config (via next.config.js) and changing my library's module and moduleResolution to ES2015 and Node respectively.What can I do to get tree shaking working properly and reduce my bundle size?