• Best Way To Build And Publish Angular Library (v10)

  • 05 – Publish Angular Library To Local npm

    Lesson List

    In this lesson, we will see how can we build our angular library and also will look into how can we publish the angular library to local npm and use it.

    Build Angular Library

    We can use the library in locally importing through the project folder but at the user end actual implementation is that the user will install the package and it will be downloaded in the node_modules folder
    So for that, we will first build our angular library which will create a bundle in the dist folder.

    # ---> angular workspace folder.
    ng build news-twentyfour

    Build Angular Library
    This command will create a dist folder and inside this folder, our compiled library is stored.

    Publishing Library to Local npm

    As we already have built the library but for the npm package will have to build this library as an npm package, and then we can publish it to the local node package manager’s registry.
    So will go to our dist/news-twentyfour/ folder and will create the npm pack

    # --->  folder: dist/news-twentyfour
    npm pack

    npm pack Angular Library
    This will make a Pack (target) file with a news-twentyfour-0.0.1.tgz.
    Locally Publishing has done..!! Now we can use this library in any angular application.
    So lets quickly try to install the library into another angular application.

    # --->  folder: other angular workspace
    npm install <path to folder>/dist/news-twentyfour/news-twentyfour-0.0.1.tgz

    Installing Angular Library

  • Enable Notifications    OK No thanks