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.
- name : name of the library.
The name type is string.
ng generate library options
ng generate library accepts 5 different types of options.
- entry-file
- prefix
- skip-install
- skip-package-json
- skip-ts-config
| Option | Description | Type | Default Value |
|---|---|---|---|
| entry-file | The path at which to create the library's public API file, relative to the workspace root. | string | public-api |
| prefix | A prefix to apply to generated selectors. Aliases: -p | string | lib |
| skip-install | Do not install dependency packages. | boolean | false |
| skip-package-json | Do not add dependencies to the "package.json" file. | boolean | false |
| skip-ts-config | Do 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. | boolean | false |
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)