首页 > 其他分享 >模块联邦-文件配置

模块联邦-文件配置

时间:2022-09-05 15:48:29浏览次数:72  
标签:文件 false remoteEntry ModuleFederationPlugin microapp js 模块 联邦 situation

exposes - 提供共享组件

+ const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');

module.exports = {
  // ...
  configureWebpack: {
+   optimization: {
+     splitChunks: false // 提供共享组件时,必须配置为false
+   },
+   plugins: [
+     new ModuleFederationPlugin({
+       name: 'situation_microapp_share',
+       filename: 'remoteEntry.js', // 另外一个应用html中引入的模块联邦入口文件
+       library: { type: 'window', name: 'situation_microapp_share' }, // 增加library,一定注意type 是 window
+       exposes: {
+         './comps': './src/expose/components/index.js',
+         './search': './src/expose/search/index.js'
+       }
+     })
+   ]
  }
  // ...
};

exposes&remotes - 提供&使用共享组件

+ const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
+ const shareAddr =  '/microapps/situation-microapp-share/remoteEntry.js'

; module.exports = { // ... configureWebpack: { + optimization: { + splitChunks: false // 提供共享组件时,必须配置为false + }, + plugins: [ + new ModuleFederationPlugin({ + name: 'sheet_situation', + filename: 'remoteEntry.js', // 另外一个应用html中引入的模块联邦入口文件 + library: { type: 'window', name: 'sheet_situation' }, // 增加library,一定注意type 是 window + exposes: { + './comps': './src/expose/components/index.js', + } + }), + new ModuleFederationPlugin({ + remotes: { + 'situation_microapp_share': `situation_microapp_share@${shareAddr}` + }, + }), + ] } // ... };

警告

特别注意:

 

 加如下代码可解决:

optimization: {
  splitChunks: false
};

原因分析:不加上述代码,执行打包后会生成chunk-vendors.43d3c6d0.js,该文件会抽取公共js,在html引入,且在app.jsremoteEntry.js之前执行。若不加上述代码,公共js会打包到各个js文件中。在MDF其他模块remotes的时候,若配置了分包,在引用remoteEntry.js的时候会执行不到公共 js 文件,故会报此错。若不启用分包,在 MDF 其他模块引用remoteEntry.js的时候,公共 js 会打包到单个文件中,故正常运行。

标签:文件,false,remoteEntry,ModuleFederationPlugin,microapp,js,模块,联邦,situation
From: https://www.cnblogs.com/lxbwxj/p/16658368.html

相关文章

  • (Spring)文件上传和下载
    文件上传的时候,浏览器将图片以MultipartFile的形式传到服务器,服务器将保存完的图片名响应给浏览器。文件下载的时候,浏览器收到图片名,再向服务器请求图片资源,服务器以流的......
  • Python读取txt文件
    F.read()和F.readlines():1#Python读取txt2defFread():3print('-----readby.read()-----')4withopen('test.txt',encoding='utf-8')asfile:5......
  • linux 十六进制查看文件hexdump
     hexdump-Ca.txthexdump-ca.txt ......
  • 下载前端项目中自带的文件到本地
    functiondownload(down_questionNo,type){$.ajax({url:"/comtion-web/doc/"+down_questionNo+type,//本地文件存放的位置type:"GET",async:false,mimeType......
  • 干货 | REST-assured 获取日志到文件并结合 Allure 报告进行展示
    ⬇️点击“下方链接”,提升测试核心竞争力!>>更多技术文章分享和免费资料领取使用Rest-assured集合Allure运行完用例之后,在生成的报告中只有断言信息,没有请求的日志信......
  • 干货 | web自动化总卡在文件上传和弹框处理上?
    ⬇️点击“下方链接”,提升测试核心竞争力!>>更多技术文章分享和免费资料领取在有些场景中,需要上传文件,而Selenium无法定位到弹出的文件框,以及网页弹出的提醒。这些都是需......
  • 设置Windows的pip镜像配置文件 pip.ini
    1.前言首先来看看有什么pip镜像地址清华https://pypi.tuna.tsinghua.edu.cn/simple豆瓣http://pypi.douban.com/simple/阿里http://mirrors.aliyun.com/pypi/simple......
  • .net通过iText操作pdf文件实现查找关键字签字盖章(新)
    因为上一篇文章确认有问题,后面复测发现bug,现在重新写了,是基于iText写的,复测多次,基本上没问题了。其他需要使用者自行扩展了直接贴代码吧。1usingiText.IO.Image;......
  • C/C++下读取ENVI栅格文件格式
     ENVI使用的是通用栅格数据格式,包含一个简单的二进制文件(asimpleflatbinary)和一个相关的ASCII(文本)的头文件。   利用其他语言如C/C++等直接读取ENVI的数据,则可以......
  • golang中读取配置文件的包go-ini/ini
    思考首先,在一个初始项目开始前,大家都要思考一下各种程序配置,写在代码中好吗?API的错误码硬编在程序中,合适吗?DB句柄谁都去open,好吗?获取分页等公共参数,不统一管理起来,好......