Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Entry Points

In Angular libraries, an entry point refers to a module or a set of modules that are exposed and can be imported by consumers of the library. There could be a single entry point versus multiple entry points. For smaller libraries, a single entry point might be appropriate, while larger libraries could benefit from multiple entry points to manage bundle size.

An Angular library with a single entry point is not tree-shakable by default. It is important to consider that when designing entry points. If bundle size is a concern, multiple entry points might be the way to go.

Single Entry Point:

In this approach, the library provides a single module that encapsulates all the functionality and components of the library. Consumers of the library only need to import one module to access all the features provided by the library. It simplifies the initial setup for consumers, as they only need to manage one import statement.

Advantages: Simplicity: Consumers have an easier time getting started, as they only need to import a single module. Consistency: The library maintains a unified and consistent API for all its features. Easier Maintenance: Internal changes within the library don’t impact consumers as long as the public API remains stable.

Disadvantages: Bundling Size: If the library contains a lot of features, a single entry point might lead to larger bundle sizes for consumers, even if they only use a subset of the features. Consumers who only need a small portion of the library’s features might end up including unused code in their bundles.

Multiple Entry Points:

In this approach, the library provides multiple modules, each corresponding to a specific feature or set of features. Consumers can import only the modules they need, reducing the risk of including unused code in their bundles. It allows for better fine-tuning of the bundle size, as consumers only import the necessary modules.

Advantages: Smaller Bundles: Consumers can import only the specific modules they need, leading to smaller bundle sizes. Optimized Performance: Reduced bundle sizes can lead to better application performance, especially in scenarios with limited bandwidth or slower networks.

Disadvantages: Complexity: Consumers need to manage multiple import statements for different modules, which can be more challenging, especially for larger libraries. Potential Duplication: If multiple modules share common dependencies, consumers might end up with duplicated code in their bundles.