Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
126 views
in Technique[技术] by (71.8m points)

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

Ideally, I'd like to create a stand-alone Angular 2 component (with tests) and then re-use it between two or three different Angular 2 sites. What are the good ways to achieve this? And a bonus question - do any 3rd party Angular 2 components exist?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...