Publish An Angular Library

by
Tags: ,
Category: ,

One of the Angular framework’s highest-profile core features is NgModules,
which, as the name implies, allow you to modularize your code.

NgModules are similar in concept to JavaScript Modules, but are specific to Angular, and provide even finer-grained options.

If you are working in an environment where you have more than one application and want to share code among them, or if you have functionality that you would like to share with the rest of the Angular programming community, the best way to do that is to distribute your modules as Angular Libraries.

If you have worked with Angular at all, you should be familiar with the concept of Angular libraries – they are among the npm modules that are listed in the dependencies section of your project’s package.json file. Angular itself is provided as a set of libraries, including @angular/core and @angular/common.

Until recently, however, creating an Angular Library has been difficult. Documentation was hard to find, and while there were a few projects that theoretically would package your code for you, none of the ones that we tried worked particularly well.

Fortunately, Google has now published a document detailing the Angular Package Format, and this has made the process easier.

Based on that document, a new project has emerged that you can use to package your library – ng-packagr.
We have been using this for a couple of months now, and it works very well, and is compatible with both Angular 4 and Angular 5.

For a further example of how to use ng-packagr, see ng-packaged, an example project by the same author.

Chariot Training and Consulting

Chariot Solutions provides Training and Consulting for Angular and other technologies.