# webpack.config.js
```javascript
const path = require("path");
const { ModuleFederationPlugin } = require("../../").container;
const rules = [
{
test: /\.js$/,
include: path.resolve(__dirname, "src"),
use: {
loader: "babel-loader",
options: {
presets: ["@babel/react"]
}
}
}
];
const optimization = {
chunkIds: "named", // for this example only: readable filenames in production too
nodeEnv: "production" // for this example only: always production version of react
};
const stats = {
chunks: true,
modules: false,
chunkModules: true,
chunkOrigins: true
};
module.exports = (env = "development") => [
// For this example we have 3 configs in a single file
// In practice you probably would have separate config
// maybe even separate repos for each build.
// For Module Federation there is not compile-time dependency
// between the builds.
// Each one can have different config options.
{
name: "app",
mode: env,
entry: {
app: "./src/index.js"
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist/aaa"),
publicPath: "dist/aaa/",
// Each build needs a unique name
// to avoid runtime collisions
// The default uses "name" from package.json
uniqueName: "module-federation-aaa"
},
module: { rules },
optimization,
plugins: [
new ModuleFederationPlugin({
// List of remotes with URLs
remotes: {
"mfe-b": "mfeBBB@/dist/bbb/mfeBBB.js",
"mfe-c": "mfeCCC@/dist/ccc/mfeCCC.js"
},
// list of shared modules with optional options
shared: {
// specifying a module request as shared module
// will provide all used modules matching this name (version from package.json)
// and consume shared modules in the version specified in dependencies from package.json
// (or in dev/peer/optionalDependencies)
// So it use the highest available version of this package matching the version requirement
// from package.json, while providing it's own version to others.
react: {
singleton: true // make sure only a single react module is used
}
}
})
],
stats
},
{
name: "mfe-b",
mode: env,
entry: {},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist/bbb"),
publicPath: "dist/bbb/",
uniqueName: "module-federation-bbb"
},
module: { rules },
optimization,
plugins: [
new ModuleFederationPlugin({
// A unique name
name: "mfeBBB",
// List of exposed modules
exposes: {
"./Component": "./src-b/Component"
},
// list of shared modules
shared: [
// date-fns is shared with the other remote, app doesn't know about that
"date-fns",
{
react: {
singleton: true // must be specified in each config
}
}
]
})
],
stats
},
{
name: "mfe-c",
mode: env,
entry: {},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist/ccc"),
publicPath: "dist/ccc/",
uniqueName: "module-federation-ccc"
},
module: { rules },
optimization,
plugins: [
new ModuleFederationPlugin({
name: "mfeCCC",
exposes: {
"./Component": "./src-c/Component",
"./Component2": "./src-c/LazyComponent"
},
shared: [
// All (used) requests within lodash are shared.
"lodash/",
"date-fns",
{
react: {
// Do not load our own version.
// There must be a valid shared module available at runtime.
// This improves build time as this module doesn't need to be compiled,
// but it opts-out of possible fallbacks and runtime version upgrade.
import: false,
singleton: true
}
}
]
})
],
stats
}
];
```
# src/index.js
```javascript
// Sharing modules requires that all remotes are initialized
// and can provide shared modules to the common scope
// As this is an async operation we need an async boundary (import())
// Using modules from remotes is also an async operation
// as chunks need to be loaded for the code of the remote module
// This also requires an async boundary (import())
// At this point shared modules initialized and remote modules are loaded
import("./bootstrap");
// It's possible to place more code here to do stuff on page init
// but it can't use any of the shared modules or remote modules.
```
# src/bootstrap.js
```jsx
import ReactDom from "react-dom";
import React from "react"; // <- this is a shared module, but used as usual
import App from "./App";
// load app
const el = document.createElement("main");
ReactDom.render(<App />, el);
document.body.appendChild(el);
// remove spinner
document.body.removeChild(document.getElementsByClassName("spinner")[0]);
```
# src/App.js
```jsx
import React from "react";
import ComponentB from "mfe-b/Component"; // <- these are remote modules,
import ComponentC from "mfe-c/Component"; // <- but they are used as usual packages
import { de } from "date-fns/locale";
// remote modules can also be used with import() which lazy loads them as usual
const ComponentD = React.lazy(() => import("mfe-c/Component2"));
const App = () => (
<article>
<header>
<h1>Hello World</h1>
</header>
<p>This component is from a remote container:</p>
<ComponentB locale={de} />
<p>And this component is from another remote container:</p>
<ComponentC locale={de} />
<React.Suspense fallback={<p>Lazy loading component...</p>}>
<p>
And this component is from this remote container too, but lazy loaded:
</p>
<ComponentD />
</React.Suspense>
</article>
);
export default App;
```
# index.html
```html
<html>
<head>
<style>
.spinner {
font-size: 10px;
margin: 50px auto;
text-indent: -9999em;
width: 11em;
height: 11em;
border-radius: 50%;
background: #595959;
background: linear-gradient(
to right,
#595959 10%,
rgba(89, 89, 89, 0) 42%
);
position: relative;
animation: spin 1.4s infinite linear;
transform: translateZ(0);
}
.spinner:before {
width: 50%;
height: 50%;
background: #595959;
border-radius: 100% 0 0 0;
position: absolute;
top: 0;
left: 0;
content: "";
}
.spinner:after {
background: white;
width: 75%;
height: 75%;
border-radius: 50%;
content: "";
margin: auto;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<!-- A spinner -->
<div class="spinner"></div>
<!-- This script only contains bootstrapping logic -->
<!-- It will load all other scripts if necessary -->
<script src="/dist/aaa/app.js" async></script>
<!-- These script tags are optional -->
<!-- They improve loading performance -->
<!-- Omitting them will add an additional round trip -->
<script src="/dist/bbb/mfeBBB.js" async></script>
<script src="/dist/ccc/mfeCCC.js" async></script>
<!-- All these scripts are pretty small ~5kb -->
<!-- For optimal performance they can be inlined -->
</body>
</html>
```
# src-b/Component.js
```jsx
import React from "react";
import { formatRelative, subDays } from "date-fns";
// date-fns is a shared module, but used as usual
// exposing modules act as async boundary,
// so no additional async boundary need to be added here
// As data-fns is an shared module, it will be placed in a separate file
// It will be loaded in parallel to the code of this module
const Component = ({ locale }) => (
<div style={{ border: "5px solid darkblue" }}>
<p>I'm a Component exposed from container B!</p>
<p>
Using date-fn in Remote:{" "}
{formatR
野生的狒狒
- 粉丝: 3398
- 资源: 2437
最新资源
- 基于蒙特卡洛抽样的电动汽车充电负荷计算(matlab代码版) 主要内容:代码主要主要研究的的是大规模电动汽车的蒙特卡洛模拟,包括电动汽车起始充电时间以及每日行使里程的概率密度分布,在此基础上,进一步计
- MATLAB代码:基于粒子群算法的含风光燃储微网优化调度 关键词:微网优化调度 粒子群算法 风光燃储 参考文档:《基于多目标粒子群算法的微电网优化调度-王金全》仅参考部分模型,非完全复现 优势:代码
- kmeans聚类,肘部法确定聚类个数 代码对数据先进行归一化然后聚类 可设定聚类个数范围,根据肘部法选择合适的聚类个数 可求得每类的具体数据 matlab代码,备注清楚,更改为自己的数据和要求即可
- 同步机VSG DFIG双馈风电机组同步机控制,并网端电源分为理想电源或同步发电机 机组1.5MW,采用控制策略如图片所示 (附赠同步机简易模型)
- P3分布参数拟合与ks检验,累计概率密度画图 对数据进行3参数拟合(形状、尺度、位置参数),可设置ks检验的显著性水平 matlab代码,备注清楚,更改为自己的数据即可
- FLAC3D水力压裂例子,可以拿来参考,有单孔和双孔
- 基于高频脉振电压注入的PMSM无传感器控制 无感控制,高频电压注入 1.包括位置观测器构成是带通滤波器加低通滤波器,采用PLL锁相环,是离散模型 2.也有连续模型,用的是龙贝格观测器提取转子位置和转速
- 拉锥光纤,镀膜、耦合、光栅…… Rsoft beamprop,光纤仿真,光子晶体光纤仿真
- 基于floyd算法的路径规划算法matlab代码,求解常见的路径规划问题 内含算法的注释,模块化编程,新手小白可快速入门 佛洛依德算法,路径规划算法,栅格地图
- 二维互相关随机场模拟实践,保姆级教程 基于matlab与flac6.0的乔列斯基分解的中点法模拟岩土体互相关随机场 自相关函数可以选择:指数型、高斯型、二阶自回归型、指数余弦型、三角型自相关函数 案例
- STM32环形串口队列程序 大数据串口收发 实时不丢包 串口程序平常产品开发中编写或移植的程序并亲自测试通过,均为工程文件格式,可直接编译使用 该程序为大数据量吞吐的串口收发例程,中断接收,边收边
- MCGS与三菱变频器通讯基于MODBUS-RTU程序 ~ 可以通过触摸屏控制变频器正反转,运行停止,还能监视变频器的运行频率,输出频率,输出电压,输出电流以及转速 MCGS嵌入版7.7软件打开
- svr支持向量机回归预测 案例提供数据进行归一化处理,对训练数据训练,对测试集预测,并计算mae、rmse、R2、mre等误差指标 matlab代码,备注详细,根据自己需要修改案例数据即可
- pytho面试资源库(含基础题和面试真题带答案)
- stm32低压无感BLDC方波控制方案 MCU是ST32M0核 负载的ADC反电动势采样 1.启动传统三段式,强拖的步数少,启动快,任意电机基本可以顺利启动切闭环; 2.配有英非凌电感法入算法; 3
- 永磁同步电机滑模控制的直接转矩控制的matlab仿真 SMC DTC直接转矩控制加滑膜控制 转速环调节器 磁链和转矩调节器 磁链和转矩的计算SVPWM矢量控制 含有报告
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈