These are all steps, if it is not clear, let me know. When you create two cli projects:
1) Export the component that you want to use from the library project:
@NgModule({ ... exports: [MyComponent] ...
2) Install ng-packagr:
npm install ng-packagr
3) Add two files to the library project, ng-package.json and public_api.ts:
The contents of ngpackage.json:
{ "$schema": "./node_modules/ng-packagr/ng-package.schema.json", "lib": { "entryFile": "public_api.ts" } }
4) Export the module that you want to use in the main project:
export * from './src/app/modules/whatever.module'
5) In the library project, edit the package.json file containing this:
"scripts": { ... "packagr": "ng-packagr -p ng-package.json" }
6) Run npm run packagr , and once the process is complete, you will find the dist folder in the root of your project. This is your component library.
7) cd to the dist folder and run the npm package. This will create a file in the root of the dist folder.
8) Then you can publish it to npm or use it directly from bitpack, github, etc. Just add the dependency in the .json package of the main project.
9) After installation, you can import your component into any app.module.ts applications by including it in your @NgModule import array ...
import { HeaderModule } from 'my-package-name'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, HeaderModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }