Skip to content
Discussion options

You must be logged in to vote

Right, so the question we need to answer is, why do barrel-files not make tree shaking just work?

Barrel files tend to be problematic because bundlers often can't prove that dropping some code is ok, because it was side-effect free. Mostly we see this problem with icon libraries, or libraries that pack a lot of utilities, for that Next.js has. way to rewrite the imports for you, https://nextjs.org/docs/app/api-reference/config/next-config-js/optimizePackageImports, but it might be negatively be impact by side-effects.

Here's a thread that discusses barrel files: webpack/webpack#16863 (comment)

If you search around, you'll find many that say barrel files are anti-pattern.

I think there's a…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@Mr-Meshky
Comment options

@Mr-Meshky
Comment options

@icyJoseph
Comment options

Answer selected by Mr-Meshky
@Mr-Meshky
Comment options

@icyJoseph
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants