Get Started with your first Angular Library

A step-by-step tutorial.

Michael Karén
5 min readSep 27, 2018

I have been copy-pasting code between projects because I did not find an easy way around it. But with Angular 6 creating libraries got a lot easier so now there are no more excuses for copy-pasting.

In this article, I will create a library and then use it in another project. I will not go too much into details, and what different config files are for but will try to keep this tutorial as short as possible for getting that first library working.

Creating the library

To start when using the CLI to build a library you first need to create a workspace. In Angular 6 we can have one workspace with several applications or libraries.
If you do not yet have the Angular CLI installed globally go ahead and do it first.

npm install -g @angular/cli
ng new
libraries

Now that this is done you can create your first library.

cd libraries
ng generate library
lib-shared --prefix mk

Now you will have a projects folder with your first library called lib-shared.

--

--

Michael Karén

Frontend Architect • JavaScript Enthusiast • Educative.io Author • ngVikings organizer.