Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Next.js 具有独立服务器的Nextjs模块联合_Next.js_Webpack Module Federation - Fatal编程技术网

Next.js 具有独立服务器的Nextjs模块联合

Next.js 具有独立服务器的Nextjs模块联合,next.js,webpack-module-federation,Next.js,Webpack Module Federation,我正在尝试在nextjs应用程序之间使用模块联合(webpack 5)。 我从(两个nextjs应用程序)开始,一切都按预期进行。从我的观点来看,问题在于,只有当我在同一台主机上安装了两个应用程序时,这才有效。 上的相关网页包配置部分如下(在其他应用中相同) 。。。。 遥控器:{ next1:isServer ?路径解析( __dirname, “./next1/.next/server/static/runtime/remoteEntry.js” ) :“next1”, }, ... 如果我

我正在尝试在nextjs应用程序之间使用模块联合(webpack 5)。 我从(两个nextjs应用程序)开始,一切都按预期进行。从我的观点来看,问题在于,只有当我在同一台主机上安装了两个应用程序时,这才有效。 上的相关网页包配置部分如下(在其他应用中相同)

。。。。
遥控器:{
next1:isServer
?路径解析(
__dirname,
“./next1/.next/server/static/runtime/remoteEntry.js”
)
:“next1”,
},
...
如果我只是删除服务器配置,它将无法工作


可以在nextjs应用程序之间使用模块联合,而无需通过文件夹路径配置远程服务器,并仅通过url引用远程应用程序?

这是可能的,但它不能与SSR一起使用。只需将遥控器留给客户端的全局:

//next.config.js
....
遥控器:{
next1:“next1”,
},
...
创建组件并导入远程文件:

//component.js
常量组件=(等待导入(“next1/Component”)。默认值
导出默认组件
最后,在页面中,延迟加载禁用SSR的远程组件:

//mypage.js
从“下一个/动态”导入动态
const RemoteComponent=动态(
()=>导入('../components/component.js'),
{ssr:false}
)
常量MyPage=()=>()
导出默认MyPage
这里有一个工作示例:


代码:

是的,我知道,但我的问题与SSR功能有关。在我看来,nextjs中的SSR和模块联合是这项技术的真正附加值。