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

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

问题描述

是否有可能在我的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个模块将具有组件,但Main App会在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天全站免登陆