10 ms·
Locally, never ever use barrel files. If you manage the entire project, just import the specific file you need. However when exporting a public/published modul
by corbezzoli 3y ago
Locally, never ever use barrel files. If you manage the entire project, just import the specific file you need.
However when exporting a public/published module it can become onerous to ask the user to import 7 files instead of 7 items from one module.
In a perfect world, this would not be much of an issue because tools would cache these resolutions/imports and their treeshaken code. In the current world, you could prepackage your project even on Node, so that there’s only one file to load, and no extra unused code.
- akira2501 3y ago> However when exporting a public/published module it can become onerous to ask the user to import 7 files instead of 7 items from one module. Plenty of large single units in almost any language are _developed_ this way, but is there any particular reason they are _deployed_ that way? It really seems like a distribution packaging issue.
- corbezzoli 3y agonpm will take in anything that has a package.json file with two fields, so it’s un/fortunately rather dumb. Nothing stops you from prepacking your files, but a lot of node developers are ironically allergic to build tools.
- Vinnl 3y agoThe author says it's fine to add a barrel file for a public package; they're just saying you shouldn't add a barrel file for every folder: https://infosec.exchange/@marvinh/111203114104449172 https://infosec.exchange/@marvinh/111203114104449172