Bacancy Bacancy
      • About Company
      • Resources

      About Company

      About Us Leadership Team Customer Reviews Awards & Recognition
      Infrastructure Our Locations Partnership

      Resources

      Press Room Blog Insights
      We are great place to work certified™

      Building and Sustaining High-Trust, High-Performance Culture

      Get Quote
    • Engagement Models

      Hiring Software Developers becomes easier with just a few clicks.

      Software Development Outsourcing

      End-to-end delivery of custom solutions aligned to your roadmap.

      Staff Augmentation

      Scale your in-house team with pre-vetted specialists on demand.

      Dedicated Teams

      Get dedicated engineers who work exclusively on your project.

      • Enterprise Services
      • IT Services
      • Data Analytics
      • Cloud Services
      • AI & ML
      • Platforms

      Enterprise Services

      Digital Transformation Business Process Automation Digital Product Engineering Enterprise App Development Custom Software Development

      IT Services

      Legacy App Modernization DevOps & SRE Full Stack Development AI Testing & QA Automation

      Data Analytics

      Data Visualization & Reporting Data Engineering & Pipelines Data Science & Predictive Analytics Business Intelligence

      Cloud Services

      Cloud Strategy & Consulting Cloud Migration & Modernization Multi Cloud Management

      AI & ML

      AI Development Agentic AI Generative AI Computer Vision Machine Learning & MLOps

      Platforms

      Salesforce SAP ServiceNow Microsoft Dynamics Snowflake
      High-quality, Cost-effective IT Outsourcing

      Schedule a free discovery session to explore your needs and find tailored solutions with no obligation.

      explore all services
    • Industries
      Healthcare Fintech Real Estate
      Logistics Education Retail & Ecommerce
      Let's Grow Together! Get Quote
      • Front End
      • Backend
      • Mobile
      • Databases
      • DevOps & Infra
      • AI & Data Stack
      • Vibe Coding

      Front End

      React.js Next.js Angular Vue.js TypeScript
      Your Very Own UI/UX Architects

      Experience smooth navigation and user-friendly designs with our front-end expertise.

      Hire Frontend Developer

      Backend

      Node.js Python Java Spring Boot Laravel .NET C# Golang FastAPI
      Server Solutions To Change Power Dynamics

      Transform your data into digital experiences with optimized coding standards.

      Hire Backend Developer

      Mobile

      iOS Android Flutter React Native
      Innovating Mobile-Friendly App Solutions

      Create dynamic mobile apps that make your brand stand out from the crowd.

      Hire Mobile App Developer

      Databases

      PostgreSQL MongoDB MySQL Redis Supabase
      Dedicated Talent With Skilled Approach

      Bring your digital visions to life with a hired resource at your convenience.

      Hire Dedicated Developer

      DevOps & Infra

      AWS Azure Google Cloud Docker Kubernetes Terraform
      Redefining Scalable Digital Infrastructures

      Make your data accessible worldwide at will, and leave the stress behind.

      Get Quote

      AI & Data Stack

      OpenAI LangChain LlamaIndex Apache Spark Airflow Tableau PowerBI Databricks
      Guiding Decisions With Data-Driven Insights

      Transition from your gut calls to actionable insights with our rich Data Science expertise.

      Get Quote

      Vibe Coding

      Base44 Claude Code Cursor Lovable Github Copilot
      Your AI-Native Development Team

      Skip the boilerplate. Our vibe coding experts use AI-first tools to go from prompt to product, fast.

      Hire Vibe Coding Developer
  • Case Studies
  • Contact Us
Find a Developer book a 30 min call
      • About Us
      • Leadership Team
      • Customer Reviews
      • Awards & Recognition
      • Infrastructure
      • Our Locations
      • Partnership
      • Press Room
      • Blog
      • Insights
      • Digital Transformation
      • Business Process Automation
      • Digital Product Engineering
      • Enterprise App Development
      • Custom Software Development
      • Legacy App Modernization
      • DevOps & SRE
      • Full Stack Development
      • AI Testing & QA Automation
      • Data Visualization & Reporting
      • Data Engineering & Pipelines
      • Data Science & Predictive Analytics
      • Business Intelligence
      • Cloud Strategy & Consulting
      • Cloud Migration & Modernization
      • Multi Cloud Management
      • AI Development
      • Agentic AI
      • Generative AI
      • Computer Vision
      • Machine Learning & MLOps
      • Salesforce
      • SAP
      • ServiceNow
      • Microsoft Dynamics
      • Snowflake
    • Healthcare
    • Fintech
    • Real Estate
    • Logistics
    • Education
    • Retail & Ecommerce
      • React.js
      • Next.js
      • Angular
      • Vue.js
      • TypeScript
      • Hire Frontend Developer
      • Node.js
      • Python
      • Java
      • Spring Boot
      • Laravel
      • .NET
      • C#
      • Golang
      • FastAPI
      • Hire Backend Developer
      • iOS
      • Android
      • Flutter
      • React Native
      • Hire Mobile App Developer
      • PostgreSQL
      • MongoDB
      • MySQL
      • Redis
      • Supabase
      • Hire Dedicated Developer
      • AWS
      • Azure
      • Google Cloud
      • Docker
      • Kubernetes
      • Terraform
      • Get Quote
      • OpenAI
      • LangChain
      • LlamaIndex
      • Apache Spark
      • Airflow
      • Tableau
      • PowerBI
      • Databricks
      • Get Quote
      • Base44
      • Claude Code
      • Cursor
      • Lovable
      • Github Copilot
      • Hire Vibe Coding Developer
  • Case Studies
  • Contact Us
  • Find a Developer
  • book a 30 min call
Angular CLI

How to Create Your Own Library with Angular CLI (Angular Version 8)

Aishwary Rawat
Aishwary Rawat Director of Engineering
Last Updated on March 10, 2025 | Written By: Aishwary Rawat

It’s been 3+ years since I have been working on Angular. From AngularJS to Angular 8, I have served my expertise on different Angular projects; meanwhile, I have used many different third-party packages(libraries). But each library has its interface. Suppose you want to extend that library feature by creating your library, thanks to the Angular team, as they provided the features to build your very own library. I am writing this blog to make you understand how you can create your project library.

Table of contents:

1. Introduction

2. Process

3. Create your Angular Library

4. Generate library build

5. Understanding the Project Library structure

6. Test Project Library into Application

7. Conclusion

8. FAQs

The version I have used for this demo:

Angualr CLI

Note:Note: If you have not installed the AngularCLI, I would like to request you to open a terminal and type.

npm i -g angular-cli

Introduction: Angular CLI

Angular CLI helps to create a new workspace for us at the time of using `ng new`

In our workspace, we will have two projects:

  • A library project
  • It is the library of components and services that we want to provide. This is the code which we will publish to npm, for example.

  • An application project
  • It will be only used to create Angular component library; Sometimes, it can be used as documentation and example usage of the library.

Process

  • Create a new workspace with the name `ng-components-app` using Angular CLI
  • ng-components-app is the test application for testing our library: ng-components-lib
  • Generate Angular library with named:`ng-components-lib` using `ng g library ng-components-lib` command
  • Our Generated library will have the prefix of uic to identify our library.
  • For testing our library ng-components-lib, We will import ng-components-lib as
  • a library into our ng-components-app application.

  • After completing the above steps, we will generate project build and then use the library in another angular project

Create an Angular Library

Now let’s create Angular Workspace and then create the project Library by using the below command:

ng new components-app --style=scss --create-application=false
cd components-app
ng g library components-lib --prefix=uic

2
3

Notice: we used the –prefix flag to make our library components to be distinct. If we do not use it, then Angular CLI will take `lib` by default.

ALWAYS: keep the habit of using a prefix when generating a project library.

Now, let’s understand what generated library command will do:

  • Will add a new `components-lib` project in angular.json file.
  • Will add `ng-packagr` dependencies to our package.json
  • Will add a reference to the `components-lib` build path in tsconfig.json
  • We will create sources for our library in `projects/components-lib` folder.

The `projects/components-lib` folder inside our application contains a component and a service inside a NgModule. Our Application’s angular.json is updated with a project of type of ‘library.’

You may also like to read; Top Angular Component Libraries

Updated angular.json of components-app after Generate Library

 angular.json

Let’s learn the key elements of “projects” to be generated in angular.json :

Root: It points to root folder of our library projects.

Sourcebook: It points to the root of our library’s actual source code.

project-type: It specifies this is a library as opposed to our other two projects, which are of the type: application.

Prefix: The prefix identifies that we will use in the selectors of our components. Remember, we specified ‘uic’ when we generated the library.

Architect:It specifies how Angular CLI can handle build, test, and lint for our project. In this section, the builder makes use of ng-packagr for building.

The dependency of ng-packagr in package.json

When we start to generate the library, Angular CLI realizes that it needs ng-packagr. So, `ng-packagr` added into our devDependencies in our workspace package.json: “ng-packagr”: “^4.1.0“,

Understand `components-lib` Library sources

In library “Project” folder, Angular CLI created a new module with a service and a component inside the “projects/components-lib/src/lib” folder. Also, there we can see another few more files:

public_api.ts

This is called the entry file. It determines what parts of our library are visible externally. In our application, we will export only our library parent module: `ComponentsLibModule`

package.json

This package.json file exists inside /projects/components-lib` folder specially for our library. This file will get published with our library as an npm package. When the developer installs our library using npm, it will install the dependent packages specified in package.json ng-package.json: configuration file of ng-packagr.

Now we will export the library parent module `ComponentsLibModule` in public_api.ts file. And after then we will import it to our application `src/app/app.module.ts’ file for testing.

How to Build our Library

Let’s create build of newly generated library by using below command:

ng build components-lib
It builds our library to the folder:
components-app\dist\components-lib

How to Build our Library

Testing Library in Application

We have created a workspace with the name `components-app,` which will now use to test our generated library.

Now we want to test our generated `components-lib` library is working successfully or not. For that, we will import `components-lib` as a library into our `components-app` application.

Import Library Module into the Application Module

Here we will display the default component that Angular CLI created for us in the library that is `components-lib.component.ts` file.

In `components-lib.module.ts,` exports the `components-lib.component.ts` file.

Import Library Module into the Application Module

Now, Import `ComponentsLibModule` inside `src/app/app.module.ts’ file as per the below screenshot.

6

Note: we should have to export the `components-lib.module.ts` file from `public_api.ts` file

For Example, open `public_api.ts` file and export library module as per the below-mentioned code:

export * from ‘./lib/components-lib.module’;

Displaying the ‘components-lib’ Component

We are going to add the default generated component from our library into our AppComponent template: app.component.html (Main Application Component).

Please go through the app.component.html file and put the selector of the `components-lib.component.ts` file as shown in the screenshot below.

app.component.html

Run an Application

Now simply run the application using `ng command; if it runs successfully that means library project structure has been successfully created.

9

Excellent. It is running successfully? We successfully created an angular 8 library.

Happy coding.

Please feel free to comment below if you need any further assistance.

In the next session, We will learn about `How to use Generated library in another Application’.

Leverage Expertise of our Full-stack AngularJS Development Team
Hire our Angular Developers Now!

Conclusion

So, this was about how to create an Angular Library. I hope the tutorial helped you the way you expected. For learning more about Angular, please feel free to visit Angular Tutorials.

At Bacancy, we have dedicated and enthusiastic Angular developers.
Are you looking for Angular developers? If yes, then without wasting a second, contact Bacancy and hire Angular developers.

FAQs

  • What is NPM and NG?

    NPM (Node Package Manager) is a dependency provider mainly used to manage all packages. It is a hotspot that offers us all the required packages. On the other hand, NG is Angular’s core module. Whenever an Angular app starts, the very first module to be loaded is – NG.

  • What is an Angular library?

    A library is defined as a collection of directives, components, precompiled routines that can be used across various projects. The Angular library is an Angular project with the limitation of not running it on its own. It has to be imported first and then later we can use it.

  • What is the difference between ng serve and ng build?

    The ng serve is used for fast and local developments. Without generating an output folder, unlike ng build, it builds the artifacts from the memory for fast development.

    The ng build command is used to build the application and deploy the artifacts. It builds an output folder: dist/. The command will generate the output files only one time and won’t serve them.


Expand Your Digital Horizons With Us.

Start a new project or take an existing one to the next level. Get in touch to start small, scale-up, and go Agile.


Or
E-mail us : solutions@bacancy.com

Your Success Is Guaranteed !

Related Articles

Dipal Bhavsar

November 21, 2025

AngularJS

Angular 21: Latest Features, Updates & Advancements

By : Dipal Bhavsar

Read More
Dipal Bhavsar

November 3, 2025

AngularJS

7 Easiest Ways to Use AI in Angular

By : Dipal Bhavsar

Read More
Darshan Joshi

August 25, 2025

Web Development

Top Web Development Trends Not To Miss in 2026

By : Darshan Joshi

Web development is constantly undergoing transformative changes. Whether we talk about AI-driven coding tools, serverless architectures, or sustainable web practices,...

Read More

Offices and Development Centers

Bacancy Ahmedabad Ahmedabad

15-16, Times Corporate Park, Thaltej, Ahmedabad, 380059

Bacancy Gandhinagar Gandhinagar

422-A, 4th Floor, Pragya Tower Road 11, Block 15, Zone 1, SEZ-PA Gandhinagar, 382355

Bacancy Hyderabad Hyderabad

Awfis, Level 1, N Heights, Plot No 38, Phase 2, Hitech City Hyderabad, 500081

Bacancy Mumbai Mumbai

18th Floor, Cyberone, opp. CIDCO Exhibition Centre, Sector 30, Vashi, Navi Mumbai, 400703

Bacancy Pune Pune

2nd FloorMarisoft-1, Marigold IT Park, Pune - 411014

Bacancy Bengaluru Bengaluru

Raheja Towers, 26/27, Mahatma Gandhi Rd, East Wing, Craig Park Layout, Ashok Nagar, Bengaluru, 560001

Global Presence

Bacancy New Jersey New Jersey

33 South Wood Ave, Suite 600, Iselin NJ 08830

Bacancy California California

535 Mission St 14th floor, San Francisco, CA 94105

Bacancy Massachusetts Massachusetts

501 Boylston St, Boston, MA 02116

Bacancy Florida Florida

4995 NW, 72nd Avenue, Suite 307, Miami, FL, 33166

Bacancy London London

90 York Wy, London N1 9AG, United Kingdom

Bacancy Ontario Ontario

71 Dawes Road, Brampton, On L6X 5N9, Toronto

Bacancy Australia Australia

351A Hampstead Rd, Northfield SA 5085

Bacancy UAE UAE

One Central 8th and 9th Floor - Trade Centre - Trade Centre 2 - Dubai - United Arab Emirates

Bacancy Sweden Sweden

Junkergatan 4, 126 53 Hagersten

Get in Touch

Great Place to Work

Get in Touch

cal-icon

Looking for expert advice?

Schedule a Expert Call


  • Brochure
  • Quality Assurance
  • Resources
  • Tutorials
  • Customer Reviews
  • Privacy Policy
  • FAQs
  • Press Room
  • Contact Us
  • Sitemap
  • Employee

bacancy google review 4.6
bacancy google review
bacancy clutch review 4.8
bacancy clutch review
bacancy goodfirms review 4.8
bacancy goodfirms review
iso
  • Bacancy Behance
  • Bacancy Pinterest

Copyright © 2026 BACANCY SERVICES PRIVATE LIMITED All rights reserved.