2020 年更新
您还可以使用新的Webpack 5 模块联合.
以下示例展示了如何将模块联合与 Angular 和其他技术结合使用。
- 模块联合的实现示例,由模块联合的创建者提供 https://github.com/module-federation/module-federation-examples
- 使用 Angular 和动态模块联合构建基于插件的工作流设计器的示例 https://github.com/manfredsteyer/module-federation-with-angular-dynamic-workflow-designer
- 与 Angular 的动态模块联合 https://github.com/manfredsteyer/module-federation-with-angular-dynamic
原答案
我最近一直很忙这个话题,因为很多人一次又一次地遇到同样的问题(当然是我)。如今,您经常听到微前端的概念。这个概念是关于将前端设计为可扩展和可扩展的。尤其是在很多企业都拥有这两种能力的时代Angular and React and Vue开发商。
我的研究得出以下方法:
Links :
您可以创建新的应用程序并拥有超级链接来自您的旧应用程序。 (在两个应用程序之间切换时,必须重新加载页面。)
Iframes :
软件架构师构建了一个元路由器来处理 iframe 和单页应用程序:
看看这个:
- (github 存储库)面向微前端(SPA/微服务客户端)的轻量级可靠方法 https://github.com/manfredsteyer/meta-router
元框架:
元框架允许您在之间进行通信differents
使用不同框架构建的应用程序:
这里有一些元框架的例子微前端目的。
- 单人水疗中心(官方网站)Single Spa:前端微服务的 JavaScript 框架 https://single-spa.js.org/
- FrintJs (官方网站)FrintJS:模块化 JavaScript 框架
用于构建可扩展和反应式应用程序。 https://frint.js.org/
Web 组件,即 Angular 元素:
为了处理 npm 包,您可以使用其他回答者提到的概念角元素 https://angular.io/guide/elements。您必须创建一个 shell 应用程序和另一个独立的应用程序,这些应用程序将在您的 shell 应用程序中注册为元素。
看看这个例子:构建微前端—— 角度元素 https://itnext.io/building-micro-frontend-applications-with-angular-elements-34483da08bcb
Mosaiq:布局服务
网上商店Zalando
面对同样的问题并创建了一个框架来处理该问题:
- 马赛克9https://www.mosaic9.org/ https://www.mosaic9.org/
尤其是那部分Tailor.js,一个开源系统,用于在后端层按需组装组件Go.
附言。裁缝师的灵感来自于BigPipe:管道化网页以获得高性能 https://www.facebook.com/notes/facebook-engineering/bigpipe-pipelining-web-pages-for-high-performance/389414033919/来自脸书。
插件架构
插件架构是一种在某些点调用外部代码而无需提前知道该代码的所有细节的架构。
这个 Stackoverflow 问题 https://stackoverflow.com/questions/41438198/在单页应用程序的情况下详细解释一下:
角度库
我认为正确的方法是在应用程序中使用相同的框架和该框架的相同版本(例如 Angular 7)。我更愿意花时间升级到 Angular 的打字稿版本。我希望答案对其他人有用。
其他 Stackoverflow 相关问答:
Vue.JS - 微前端方法 https://stackoverflow.com/a/49204404/6432698
微前端架构建议 https://stackoverflow.com/q/47922293/
微前端示例
- Angular 8 和 ReactJS(使用 NodeJS 服务器和 MySQL 数据库):https://github.com/billyjov/angular-react-microfrontend https://github.com/billyjov/angular-react-microfrontend
有关微前端的资源列表
https://github.com/billyjov/microfrontend-resources https://github.com/billyjov/microfrontend-resources