Skip to content
Joe Zhang edited this page Sep 1, 2021 · 2 revisions

Remote端暴露模块

  • Remote端需要实现2个特性:
    1. 提供RemoteEntry.js入口文件给Host端
    2. 将配置的模块单独打包chunk
  • 相关的配置为exposes选项,例如
exposes: {
        './Content': './src/components/Content.vue',
        './Button': './src/components/Button.js',
      },

实现原理

RemoteEntry.js需要暴露出 init(), get()两个函数供Host使用

let moduleMap = {
"./Button":()=>{return import('./button.js')},};
    const get =(module, getScope) => {
        return moduleMap[module]();
    };
    const init =(shareScope, initScope) => {
        let global = window || node;
        global.__rf_var__shared= shareScope;
    };

export { get, init };
Clone this wiki locally