DEV Community

Discussion on: Organize React Components Better with Barrel Exports

maciekgrzybek profile image
Maciek Grzybek • Edited on

First of all, great stuff with the article :) I've been using this pattern for a while now, but never knew that it's called like that :)
Is the tree shaking problem only related to next js?

Thread Thread
pcjmfranken profile image
Peter Franken

Not limited to Next. Whether your codebase is affected depends on its complexity and your bundler configuration. Running some tests is the only way to to be sure.

Figuring out what code can be safely dropped ("tree-shaken") is quite complex. Your bundler (e.g. webpack) has to look at each piece of code and figure out if it's used anywhere else in any way (deep-scope analysis).

The more ambiguous your code or deeper your import trees, the more time it would take to get this right (exponential complexity AKA best leave it for the CompSci's 😉). We want fast builds though, so at some point the bundler is just going to tap out and leave the code that it isn't sure about in.

Here's an amazing and really in-depth article for those wanting to learn more: dev.to/livechat/tree-shaking-for-j...