Next.js Discord

Discord Forum

Barrel exports, bundle size optimization and tree shaking

Unanswered
Bartholomeas posted this in #help-forum
Open in Discord
[Nextjs 13 app dir]

Hello, i moved in my project to barrel exports (as its much better to look at it during development) but then i sadly builded the project.. As you can see (and its small project for now) it increased in size.

And thats the question; its possible to somehow optimize its just con of using barrel exports?

I just have file with exports like that:
export * from "~/stores/card/card-styles-store";
export * from "~/stores/card/card-styles-store-provider";
export * from "~/stores/card/helpers";


But maybe when ill export them like that:
export {AnyComponent} from "~/stores/card/card-styles-store";
export {Blahbla} from "~/stores/card/card-styles-store-provider";
export {HelperFunctionOrsmth} from "~/stores/card/helpers";

3 Replies

barrel exports are not really a good idea, this is one of the reasons why. I recommend giving a read at this article: https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7/
@Rafael Almeida barrel exports are not really a good idea, this is one of the reasons why. I recommend giving a read at this article: https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7/
Hmm.. So i should stick with exporting everything as a separate component? 🤔

Damn, i like when ill import everything from one directory 😅
thanks! ill start read