[Solved] When using “ng generate library” what is an Angular “Library”?


An “angular library” in this context refers to self-contained Angular project that stands by itself in the projects/ directory,

An Angular Library is summarized as,

Many applications need to solve the same general problems, such as presenting a unified user interface, presenting data, and allowing data entry. Developers can create general solutions for particular domains that can be adapted for re-use in different apps. Such a solution can be built as Angular libraries and these libraries can be published and shared as npm packages.

You can see the files generated here,

CREATE projects/foobar/README.md (987 bytes)
CREATE projects/foobar/karma.conf.js (975 bytes)
CREATE projects/foobar/ng-package.json (155 bytes)
CREATE projects/foobar/package.json (136 bytes)
CREATE projects/foobar/tsconfig.lib.json (726 bytes)
CREATE projects/foobar/tsconfig.spec.json (246 bytes)
CREATE projects/foobar/tslint.json (247 bytes)
CREATE projects/foobar/src/public_api.ts (155 bytes)
CREATE projects/foobar/src/test.ts (700 bytes)
CREATE projects/foobar/src/lib/foobar.module.ts (224 bytes)
CREATE projects/foobar/src/lib/foobar.component.spec.ts (628 bytes)
CREATE projects/foobar/src/lib/foobar.component.ts (256 bytes)
CREATE projects/foobar/src/lib/foobar.service.spec.ts (333 bytes)
CREATE projects/foobar/src/lib/foobar.service.ts (135 bytes)
UPDATE angular.json (4855 bytes)
UPDATE package.json (1432 bytes)
UPDATE tsconfig.json (557 bytes)

This is added as a requirement to your own project. The idea is to allow you to package components for reuse and the command simply sets up a component in the Angular Package Format. The command ng generate library seems to be introduced in the CLI version 6.

Note it’s not quite the same as a new project, from the docs

An Angular library is an Angular project that differs from an app in that it cannot run on its own. A library must be imported and used in an app.

See Also

solved When using “ng generate library” what is an Angular “Library”?