Barrels
Barrels are a technique used to roll up exports from different modules into a single one, usually called index.ts, to simplify the imports. Barrels thus simply combine the exports of one or more other modules. By making use of the re-export functionality, you can actually create barrels.
For example, if you create a library, then it is useful to expose a single module exposing the public API to the outside world. As a consumer, barrels are useful because they let you concentrate on what you want to use and not on where symbols are located.
Here's an example of a barrel in the Angular framework: https://github.com/angular/angular/blob/master/packages/core/src/core.ts. This barrel is re-exported by https://github.com/angular/angular/blob/master/packages/core/public_api.ts ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access