Building reusable Angular NPM packages

Magnus Stuhr
Compendium
Published in
4 min readJun 11, 2018

--

My previous blog post argued that one of the most important principles of programming is to avoid code-duplication, and rather reuse existing code for the same functionality — it aimed at providing insights into how anyone could implement their own code-sharing strategy. This blog post will further elaborate on this by showing a concrete example of how you in no time can develop and publish your own Angular NPM packages that can be reused across your different applications.

The first thing we need to do when publishing our own NPM packages, is to make sure we have an NPM registry to push our packages to. If you want to push your package to a public repository, you do not need to set up any authentication. However, if you have a private NPM registry of some sort, you need to follow the authentication setup instructions for that repository, as we will not go into details about that in this post. Either way, you should end up with a .npmrc file in the root folder of your project, containing a list of the registries your application should retrieve packages from:

.npmrc

@<your_registry_name>:registry=<your_registry_url>
always-auth=true

Building and publishing NPM packages

This section includes a step-by-step guide on how to build and publish your own NPM…

--

--