在运行时从不同的服务器加载模块 [英] Loading modules from different server at runtime

查看:28
本文介绍了在运行时从不同的服务器加载模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在我的 angular 2 应用运行时从不同的服务器加载不同的模块,如果可以,我该如何实现?

Is it somehow possible to load different modules in my angular 2 app runtime, from different servers and if so, how can I achieve this?

我想让我的应用程序从隔离的服务器(A、B、C)加载整个应用程序中的不同组件,以便可以独立于主应用程序和 A 中包含的任何组件删除和更新它们,B 或 C 不会被加载.底部显示的 3 个模块将包含组件,但主应用程序将在它的 HTML 中声明它应该加载组件的位置.

I would like to have my app load different components from the overall application from isolated servers (A, B, C), so they can be taken down and updated independently from the main app and any components which are included in A, B or C won't be loaded. The 3 modules shown on the bottom would have the Components, but the Main App would declare in it's HTML where it should load the component.

更新

通过路由延迟加载不是我想要的,这 3 个模块应该是完全独立的模块,它们有自己的存储库、项目、托管和 enz.

Lazy loading through routes is not what I'm looking for, the 3 modules should be completely independent modules which have their own repository, project, hosting, enz.

推荐答案

有点晚了,但是你可以在路由中使用延迟加载机制来做你想做的事情.

A little late, but you can use the lazy-loading mechanism in routes to do exactly what you want.

本文阐述了如何从其他来源加载 webpack 模块:解决方案:动态加载独立编译的 Webpack 2 包

This article states on how to load a webpack module from another source: Solution: load independently compiled Webpack 2 bundles dynamically

在路由中,您在 loadchildren 部分定义回调:

In the routes you define a callback in the loadchildren section:

const appRoutes: Routes = [
    {path: '', component: MainComponent},
    {path: 'modulea', loadchildren: loadModuleA}
]

loadModuleA 方法如下所示:

the loadModuleA method would look like:

export function loadModuleA() {

    return new Promise((resolve, reject) => {

        // the method from the article
        loadPlugin('path/to/server/of/moduleA', (exports) => {
            // The Submodule must export ModuleA
            resolve(exports.ModuleA);
        });

    });

}

这篇关于在运行时从不同的服务器加载模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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