0

I have two Angular applications. Each have one main Module and some components. I want to have a third Angular project, that uses them. How can I do that?

I think I should somehow package each application and then install it in the new Angular project, but I think it's possible to package only Library projects, not Application projects.

I know about Angular Elements, but I think packaging each project files will end up with conflicts, because they create some common files like polyfills.js and runtime.js.

EDalet
  • 23
  • 5

1 Answers1

0

Angular Elements is the tooling to not building your App as an actual Angular Application, but it provides tooling to build your sources as a web component. If your App is more a widget and it will possibly be used by other frameworks than Angular or without a framework, you could consider this path.

Using a Library could be one option if you want to distribute your sub-apps over the NPM channel. You may be working in a corporate environment and you have wrapped the NPM packages behind a private repository / paying for private on npmjs or you are open sourcing the whole sub application. Therefore you could build a library with features reused. Your lib code is highly configurable then. I would try this path. You can extend the Lib code with schematics, to enable easier integration in other projects. Using the library has many topics to consider, like versioning of the lib.

If you are using git and you are the only consumer of the sub apps, you could checkout git`s Submodules feature and configuring sub project and third project accordingly. Then you are able to bi-directionally develop main and sub-apps.

All in all I would have a look into Angular-Libraries and schematics.

https://angular.io/guide/schematics https://blog.angular.io/schematics-an-introduction-dc1dfbc2a2b2

https://angular.io/guide/creating-libraries

Oli Erxleben
  • 131
  • 2
  • 2
  • Thanks Oliver. I actually wanted to use Angular Elements but I don't think I can do that with two projects which may have the same dependencies, because there might be conflicts. Is there a way to easily turn an application project to library? – EDalet May 10 '20 at 11:07
  • angular projects are actually workspaces ( > angular 7) and you can add multiple targets to it. You can have many apps if you want. *ng generate library my-lib* from your project root is a good starting point. Oh and the third link I pasted is also very useful to get started. :) – Oli Erxleben May 10 '20 at 11:56