How to write a reusable component / module?

Now I am writing two new websites. Both have great functionality. Is it possible with angular to write small components / modules and reuse them in other applications? What will be the project structure for it or can I use the ng-cli structure?

+5
source share
2 answers

Yes, I think it would be possible since you got a lot of angular2 plugins where you npm install something and include it in your own project. If I looked like this, I had some kind of common component, I would look at something like this and copy their project structure and how they created it. https://github.com/scttcper/ngx-toastr . This is just one example, and there are many other third-party plugins that you can use for inspiration.

+2
source

The technical answer will be as above. Regarding the management of your components that will be used in two or more projects, I can also point you to an open source project that we have released for this very purpose.

People often post small packages or store an extensive utility library in one repo. These, in my opinion, cannot achieve true reuse simply because they require too much overhead.

During this problem, we developed an open source component management system called a bit: https://github.com/teambit/bit

This makes it easy to export and reuse code components in projects and repositories. He also cares about CI, version control, and just about everything we need. You can see an example for an open source reusable component called array / diff here on a free community hub .

Feel free to try and help out with pleasure if you need anything.

+1
source

Source: https://habr.com/ru/post/1263066/


All Articles