Angular 6 delivered one of the most requested features for the Angular CLI

Angular 6 delivered one of the most requested features for the Angular CLI: support for creating and building libraries.

To create a library, you run: ng generate library <name>

This command will create a library project within your CLI workspace (ng new <project>) and configure it for testing and building.

Just like ng update and ng addng generate library is underpinned by schematics and is easy to extend and configure.

What is a library?

A library is any Angular project you can install via npm into the node_modules folder. e.g. npm install ng-date-picker.

To use a library you have to import it: import { something } from ‘library-name’;

When you run ng build it looks for libraries in your tsconfig paths and then in the node_modules folder. This behaviour enables you to develop and test libraries without having to publish them to npm. Just don’t forget to build the library first!

Libraries aren’t something you need to worry about if you are new to Angular. But once your project grows, libraries make breaking up your application simple.

 


Upgrade to Angular is a daily bite-size newsletter containing Angular newsanalysis and advice by Darryl Brown.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.