如何将有角度的应用程序嵌入另一个应用程序? [英] how to embed an angular app into another app?

查看:361
本文介绍了如何将有角度的应用程序嵌入另一个应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队开发了一个已投入生产一段时间的Angle 5应用程序,但最近我们受命让该应用程序在公司拥有的其他3个站点上运行.一个站点是使用Angular6构建的SPA,另一个站点也是SPA,但使用Angular5,而另一个站点则使用一些较旧的库,例如jQuery.

My team develop an angular 5 application that has been in production for a while, but we've been tasked recently with making the app work in other 3 sites the company owns. One site is a SPA built with Angular6, other is also a SPA but uses Angular5, while the other is using some older libraries such as jQuery.

管理层希望我们立即与Angular5 SPA集成,因此我们只是将整个应用程序导出为带有子路由的模块,然后让其他应用程序进行引导.

Management wanted us to integrate with the Angular5 SPA right away so we just exported the whole application as a module with child routes and let the other application do the bootstrap.

但是,恐怕上述方法不适用于非角度站点.这也使这两个应用程序紧密耦合,因为主机"应用程序需要了解我们应用程序的所有依赖关系,而这并不是一个琐碎的应用程序(我想说是相当大的),并安装它们,这在两个应用程序都需要不同版本的应用程序时引起了问题.相同的依赖关系,更不用说在升级依赖关系或框架本身时需要同步.我认为将应用程序嵌入更多网站时这种方法不会扩展.

But I'm afraid the above approach will not work for the non-angular site. This also tight couple both applications since the 'host' app needs to know about all dependencies of our application which is not a trivial app (I'd say is pretty big) and install them, this caused problems when both applications needed different versions of the same dependency, no to mention that we will need to sync when upgrading dependencies or the framework itself. I don't think this approach will scale when embedding the app into more sites.

我想实现更通用的实现的第一个想法是将我们的应用程序升级到Angular 6并使用自定义元素创建一个Web组件,但是我们需要支持不支持本机封装的IE11和Edge,因此我们需要进行测试我们在每个使用它的站点中使用我们的应用程序,以确保它们不会破坏我们的样式,我也不知道Web组件是否可以管理子路径.

My first idea for a more general implementation was to upgrade our app to Angular 6 and create a web component with a custom element, but we need to support IE11 and Edge which do not support native encapsulation, so we would need to test our app in every site where it is used, to make sure they are not breaking our styles, also I don't know whether a web component can manage child routes or not.

其他想法是使用iframe,但是我的问题是调整iframe的大小以适应内容,以及如何从iframe中的驻留"应用程序在主机"应用程序中添加子路由.

Other idea is to use an iframe but my problem here is the iframe resizing to adapt to the content and how to add child routes in the 'host' app from the 'resident' app inside the iframe.

是否有更好的方法来实现我们需要做的事情?

Is there a better way to achieve what we need to do?

理想的解决方案应该允许我们的应用程序在多个站点中使用(每个站点都提供特定的配置),而无需我们使用我们的应用程序来了解该站点.

The ideal solution should allow our application to be used in multiple sites (each one providing specific configuration) without us having to know about the site using our app.

感谢您的帮助.

推荐答案

最近我一直在忙于这个话题,因为许多人一次又一次地遇到相同的问题(当然是我).如今,您经常听到微前端的概念.这个概念是关于将前端设计为可扩展和可扩展的.特别是在许多公司同时拥有 Angular React Vue 开发人员的时代. 以下方法是我的研究得出的:

I've been very busy with the topic lately, because many have the same problem again and again (me, of course). Nowadays, you often hear the concept of micro-frontends. The concept is about designing the frontend to be extensible and scalable. Especially in the time when many companies have both Angular and React and Vue developers. The following approaches came out of my research:

链接:

您可以创建新应用,并从旧版应用中获取超链接. (在两个应用之间切换时,必须重新加载页面.)

You can create your new app and have a hyperlink from your legacy app. (You must have a page reload when you switch beetween the both apps.)

iframes :

一位软件架构师构建了一个元路由器来处理iframe和单页应用程序:
看看这个:

a Software architect builded a meta router to deal with iframes and single page application:
Take a look at this:

  • (github repository) A lightweight and solid approach towards micro frontends (SPAs/ clients for micro services)

元框架:

Metaframeworks允许您使用不同的框架构建的differents应用之间进行交流:
这里有一些用于 microfrontend 目的的metaframeworks示例.

Metaframeworks allow you to have a communication beetween differents apps builded using differents frameworks:
here some example of metaframeworks for microfrontend purposes.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆