How can I share an Angular 2 component between multiple Angular 2 projects?

UPDATE

OFFICIAL Angular CLI https://angular.io/guide/creating-libraries

You can create an angular2 component library (with tests) and then use it in any number of projects

Then you can publish it on npm for public use. If you want to keep it private, you can read this https://docs.npmjs.com/creating-and-publishing-private-packages

Yes, many 3rd party angular2 components exist. Here are a few from valor-software https://github.com/valor-software/ng2-plans


If you don't want to publish your library and still use it, you can create a mono repo architecture. There is a tool by ex-googlers called nx https://nx.dev/. You can create a library using it and can use it in your project https://nx.dev/latest/angular/tutorial/08-create-libs


Yeoman Generator for angular library https://github.com/jvandemo/generator-angular2-library


this is a bit late but I'd like to suggest another solution, recently released to public beta for Angular. You can wrap each component inside an ngModule (as done by most ng component libs) and then use bit to share the component between two different projects or apps. The advantages are that you can publish, install and update individual components. bit will handle the packing of the component with all its dependencies, files etc so you can then install it another project using npm/yarn. Also, you can then use bit to import the component's code into the 2nd repo, make changes and sync them back between the repos. You can take a look at the Angular with bit tutorial and guidelines (written together by teams bit and angular). Here are also some examples. Hope this helps. I'm on team bit so please feel free to ask anything and I'd love to help if I can.