最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

webpack - Reapck React Native Module federation v2 dynamic remote loading - Stack Overflow

programmeradmin7浏览0评论

I am trying to load the remote dynamically through api in new Repack.plugins.ModuleFederationPluginV2({}) as shown below.

      remotes: {
        App: `promise new Promise(resolve => {
          fetch('http://192.168.0.102:3000/config')
            .then(res => res.json())
            .then(data => {
              const { remoteName, url } = data;
              console.log(data);
        
              if (!remoteName || !url) {
                throw new Error('Invalid remote config');
              }
        
              fetch(url)
                .then(response => response.text())
                .then(code => {
                    const script = new Function(code); 
                    script();
                   resolve(globalThis[data.remoteName]);
                })
                .catch(error => console.error('Error loading remote:', error));
            })
            .catch(error => console.error('Error fetching config:', error));
        })`,
      },

Not able to load the the script in native app, am I missing anything?

my api response is

http://192.168.0.102:3000/config

{
    "config": {
        "name": "micro-version-url",
        "remoteName": "App1",
        "url": "http://192.168.0.102:9002/android/app1.container.js.bundle",
    }
}

Please help

发布评论

评论列表(0)

  1. 暂无评论