reactjs - Webpack 模块联合延迟加载 remoteEntry.js
问题描述
当我将 React 与 ReactRouter 一起使用时,我可以延迟加载应用程序的入口文件吗?remoteEntry.js
当我进入页面时,我拥有的每个应用程序都有许多文件请求。由于性能,我不想在一开始就获取它。我想在访问特定应用程序的路线时加载它们。
解决方案
new ModuleFederationPlugin({
name: 'reactParent',
filename: 'remoteEntry.js',
remotes: {
reactChild: 'reactChild@/reactChild/remoteEntry.js',
svelteChild: 'svelteChild@/svelteChild/remoteEntry.js',
vueChild: 'vueChild@/vueChild/remoteEntry.js'
}
})
将 remoteEntry.js 文件的路径放入 Webpack 配置中即可完成工作。在此示例中,我的应用程序设置为将请求代理到微前端,因此 /reactChild 被代理到特定应用程序的运行位置。
推荐阅读
- python - 未找到 BS4 模块
- flutter - 如何在颤动中并排对齐列表视图中的项目?
- asp.net-core - 使用 Html.BeginCollectionItem 从模式弹出窗口中捕获数据作为部分视图的一部分
- android - 类型与 Kotlin 通用适配器不匹配
- java - 如何使用 redis-cli 控制台列出数据?
- angular - 执行 ng serve 时的“wdm”是什么?
- entity-framework - 主体键映射到实体框架核心中不同名称的列
- python - 线程优先级解决方法
- java - 我可以使用 JNI 层在 android 应用程序中重用我的 c++ 库吗?
- php - PHP 找不到 `npm` 可执行文件