webpack 通过NextModuleFederation使用远程应用程序进行动态路由

mxg2im7a  于 5个月前  发布在  Webpack
关注(0)|答案(1)|浏览(61)

我刚开始使用next-module-federation为我们公司正在构建的一个项目。我们的目标是创建大约6-7个独立的应用程序,每个应用程序都将被分离路由。例如:

AppRemote1 - ./src/pages/index.jsx ----> /remote1
AppRemote2 - ./src/pages/index.jsx ----> /remote2
AppRemote3 - ./src/pages/index.jsx ----> /remote3

字符串
在子路由的情况下,这些将像往常一样构建在页面文件夹中的远程应用程序中。我看到有一个exposePages属性,但不知道如何将路由Map到Webpack上的remotes键中定义的远程页面。任何帮助都将非常感谢。

gev0vcfq

gev0vcfq1#

在您的例子中,如果您想将路由Map到Webpack中的remotes键中定义的远程页面,则可以使用exposePages属性。
要将路由Map到远程页面,您需要在远程的Webpack配置中配置exposePages属性。此属性允许您指定路由与远程页面入口点之间的Map。
下面是一个远程应用AppRemotel的配置示例:

// webpack.config.js of AppRemotel

module.exports = {
  // other webpack configurations
  output: {
    // output path and filename configurations
    publicPath: '/remotel/',
  },
  // other webpack configurations
  exposePages: {
    './src/pages/index.jsx': '/remotel' // map '/remotel' route to './src/pages/index.jsx' entry point
  },
  // other webpack configurations
};

字符串

相关问题