ng generate library command in Angular CLI

ng generate library command is used to create libraries in Angular applications

ng generate library syntax

ng generate library command takes one parameter i.e, name

Additionally we can pass different options as well.

ng generate library [name] [options]

or you can use shorthand syntax

ng generate lib [name] [options]

ng generate library arguments

ng generate library command takes one argument i.e, name.

  1. name : name of the library.

The name type is string.

ng generate library options

ng generate library accepts 5 different types of options.

  1. entry-file
  2. prefix
  3. skip-install
  4. skip-package-json
  5. skip-ts-config
OptionDescriptionTypeDefault Value
entry-fileThe path at which to create the library's public API file, relative to the workspace root.stringpublic-api
prefixA prefix to apply to generated selectors. Aliases: -pstringlib
skip-installDo not install dependency packages.booleanfalse
skip-package-jsonDo not add dependencies to the "package.json" file.booleanfalse
skip-ts-configDo not update "tsconfig.json" to add a path mapping for the new library. The path mapping is needed to use the library in an app, but can be disabled here to simplify development.booleanfalse

ng generate library example

For example if you want to create a library named product, use ng generate i product command.

CREATE src/app/product.library.ts (29 bytes)
Liked this post? Subscribe