DEV Community

Discussion on: How to add Barrels in TypeScript (or JavaScript)

Collapse
 
spock123 profile image
Lars Rye Jeppesen

Webpack has issues tree shaking this.

Collapse
 
javiasilis profile image
Jose

I've unfortunately learned the hard way at this. I love barreling and it does clean up your code considerably... But it harms all of the bundlers ability to tree shake (even when you have all the output for ES2017 or newer).

I'm currently undergoing a massive refactor in which I'm stripping all the barrels.

Collapse
 
bryanltobing profile image
Bryan Lumbantobing

what did you do instead. I'm planning to do the same removing the barrel. but i couldn't find the right way.

My file importing so many components that I ended up have more than 50 lines only importing components

Thread Thread
 
javiasilis profile image
Jose • Edited

To be honest, me neither. What I ended up doing was only barreling those files that I know they were going to be used together, and manually removing each of the other ones... Yes, I spent many many hours in the refactor... But it was worth it.

Plus I used type aliases (works both on Babel and TypeScript) to better index my applications.

Some comments have been hidden by the post's author - find out more