@ice/mf-runtime 1.0.2-beta.1 → 1.0.2-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -221
- package/es2017/RemoteModule.js +16 -35
- package/es2017/index.d.ts +0 -2
- package/es2017/index.js +2 -4
- package/es2017/runtime-plugin.js +5 -3
- package/es2017/types.d.ts +0 -27
- package/es2017/types.js +1 -2
- package/esm/RemoteModule.js +26 -34
- package/esm/index.d.ts +0 -2
- package/esm/index.js +2 -4
- package/esm/runtime-plugin.js +5 -3
- package/esm/types.d.ts +0 -27
- package/esm/types.js +1 -2
- package/package.json +2 -12
- package/es2017/__tests__/plugin-manager.test.d.ts +0 -1
- package/es2017/__tests__/plugin-manager.test.js +0 -294
- package/es2017/__tests__/setup.d.ts +0 -1
- package/es2017/__tests__/setup.js +0 -28
- package/es2017/plugin-manager.d.ts +0 -79
- package/es2017/plugin-manager.js +0 -134
- package/esm/__tests__/plugin-manager.test.d.ts +0 -1
- package/esm/__tests__/plugin-manager.test.js +0 -348
- package/esm/__tests__/setup.d.ts +0 -1
- package/esm/__tests__/setup.js +0 -43
- package/esm/plugin-manager.d.ts +0 -79
- package/esm/plugin-manager.js +0 -207
package/README.md
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
# @ice/mf-runtime
|
|
2
2
|
|
|
3
|
-
基于 Module Federation 的运行时工具,用于在 ice.js 应用中加载和管理远程模块。支持跨版本 React
|
|
3
|
+
基于 Module Federation 的运行时工具,用于在 ice.js 应用中加载和管理远程模块。支持跨版本 React 组件加载
|
|
4
4
|
|
|
5
5
|
## 特性
|
|
6
6
|
|
|
7
7
|
- 基于 [Module Federation 2.0](https://module-federation.io/index.html)
|
|
8
8
|
- 支持跨版本 React 组件加载
|
|
9
9
|
- 内置冲突检测和降级渲染
|
|
10
|
-
- 🔌 **增强插件机制**: 完全兼容标准 MF 运行时插件
|
|
11
|
-
- 🎯 **组件增强**: 支持 HOC、Props 注入等组件扩展机制
|
|
12
|
-
- 🛡️ **错误边界**: 内置错误处理和恢复机制
|
|
13
|
-
- 📊 **性能监控**: 支持组件加载和渲染性能追踪
|
|
14
|
-
- 🔄 **热插拔**: 运行时动态注册和移除插件
|
|
15
|
-
- 📝 **TypeScript**: 完整的类型定义支持
|
|
16
10
|
|
|
17
11
|
## 安装
|
|
18
12
|
|
|
@@ -20,220 +14,6 @@
|
|
|
20
14
|
$ npm i @ice/mf-runtime --save
|
|
21
15
|
```
|
|
22
16
|
|
|
23
|
-
## 插件机制
|
|
24
|
-
|
|
25
|
-
从 v1.0.1 开始,`@ice/mf-runtime` 支持强大的插件机制,允许在运行时动态扩展微前端功能。
|
|
26
|
-
|
|
27
|
-
### 插件类型
|
|
28
|
-
|
|
29
|
-
#### 1. 标准 MF 插件 (FederationRuntimePlugin)
|
|
30
|
-
标准 MF 插件使用原生的 `@module-federation/runtime` API 进行管理:
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
import { registerPlugins } from '@module-federation/runtime';
|
|
34
|
-
import type { FederationRuntimePlugin } from '@ice/mf-runtime';
|
|
35
|
-
|
|
36
|
-
const mfPlugin: FederationRuntimePlugin = {
|
|
37
|
-
name: 'my-mf-plugin',
|
|
38
|
-
beforeRequest: (args) => {
|
|
39
|
-
console.log('模块请求前:', args);
|
|
40
|
-
return args;
|
|
41
|
-
},
|
|
42
|
-
onLoad: (args) => {
|
|
43
|
-
console.log('模块加载后:', args);
|
|
44
|
-
return args;
|
|
45
|
-
},
|
|
46
|
-
afterResolve: (args) => {
|
|
47
|
-
console.log('模块解析后:', args);
|
|
48
|
-
return args;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// 使用原生 API 注册标准 MF 插件
|
|
53
|
-
registerPlugins([mfPlugin]);
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
#### 2. 增强插件 (EnhancedRuntimePlugin)
|
|
57
|
-
增强插件使用新的 API 进行管理,提供组件级别的扩展能力:
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
import { registerEnhancedPlugins } from '@ice/mf-runtime';
|
|
61
|
-
import type { EnhancedRuntimePlugin } from '@ice/mf-runtime';
|
|
62
|
-
|
|
63
|
-
const enhancedPlugin: EnhancedRuntimePlugin = {
|
|
64
|
-
name: 'my-enhanced-plugin',
|
|
65
|
-
|
|
66
|
-
// 组件包装器 - 支持 HOC 模式
|
|
67
|
-
wrapComponent: (WrappedComponent, context) => {
|
|
68
|
-
return function Enhanced(props) {
|
|
69
|
-
console.log(`渲染组件: ${context.remoteName}/${context.moduleName}`);
|
|
70
|
-
return <WrappedComponent {...props} />;
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
// 属性注入器
|
|
75
|
-
injectProps: (props, context) => {
|
|
76
|
-
return {
|
|
77
|
-
...props,
|
|
78
|
-
injectedProp: `来自 ${context.remoteName} 的数据`
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// 使用新的 API 注册增强插件
|
|
84
|
-
registerEnhancedPlugins([enhancedPlugin]);
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### 注册和使用插件
|
|
88
|
-
|
|
89
|
-
#### 基本用法
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
import { init, registerEnhancedPlugins, RemoteModule } from '@ice/mf-runtime';
|
|
93
|
-
import { registerPlugins } from '@module-federation/runtime';
|
|
94
|
-
|
|
95
|
-
// 注册标准 MF 插件
|
|
96
|
-
registerPlugins([mfPlugin]);
|
|
97
|
-
|
|
98
|
-
// 注册增强插件
|
|
99
|
-
registerEnhancedPlugins([enhancedPlugin]);
|
|
100
|
-
|
|
101
|
-
// 初始化运行时
|
|
102
|
-
init({
|
|
103
|
-
remotes: [
|
|
104
|
-
{
|
|
105
|
-
name: 'remote-app',
|
|
106
|
-
entry: 'http://localhost:3001/remoteEntry.js'
|
|
107
|
-
}
|
|
108
|
-
]
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// 使用远程模块(插件会自动应用)
|
|
112
|
-
function App() {
|
|
113
|
-
return (
|
|
114
|
-
<RemoteModule
|
|
115
|
-
scope="remote-app"
|
|
116
|
-
module="Button"
|
|
117
|
-
componentProps={{ text: '点击我' }}
|
|
118
|
-
/>
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
#### 使用示例插件包
|
|
124
|
-
|
|
125
|
-
我们提供了一个示例插件包 `@ice/mf-plugin-example`,包含常用的插件:
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
npm install @ice/mf-plugin-example
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
import { registerPlugins } from '@module-federation/runtime';
|
|
133
|
-
import { registerEnhancedPlugins } from '@ice/mf-runtime';
|
|
134
|
-
import {
|
|
135
|
-
errorBoundaryPlugin,
|
|
136
|
-
commonPropsPlugin,
|
|
137
|
-
developmentMFLoggingPlugin,
|
|
138
|
-
developmentEnhancedLoggingPlugin
|
|
139
|
-
} from '@ice/mf-plugin-example';
|
|
140
|
-
|
|
141
|
-
// 注册标准 MF 插件
|
|
142
|
-
registerPlugins([
|
|
143
|
-
developmentMFLoggingPlugin // MF 日志插件
|
|
144
|
-
]);
|
|
145
|
-
|
|
146
|
-
// 注册增强插件
|
|
147
|
-
registerEnhancedPlugins([
|
|
148
|
-
developmentEnhancedLoggingPlugin, // 增强日志插件
|
|
149
|
-
errorBoundaryPlugin, // 错误边界插件
|
|
150
|
-
commonPropsPlugin // 通用属性注入插件
|
|
151
|
-
]);
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### 插件开发指南
|
|
155
|
-
|
|
156
|
-
#### 错误边界插件示例
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
import { ErrorBoundary } from 'react-error-boundary';
|
|
160
|
-
|
|
161
|
-
const errorBoundaryPlugin: EnhancedRuntimePlugin = {
|
|
162
|
-
name: 'error-boundary',
|
|
163
|
-
wrapComponent: (WrappedComponent, context) => {
|
|
164
|
-
return function ErrorBoundaryWrapper(props) {
|
|
165
|
-
return (
|
|
166
|
-
<ErrorBoundary
|
|
167
|
-
fallback={<div>组件 {context.remoteName} 加载失败</div>}
|
|
168
|
-
onError={(error) => {
|
|
169
|
-
console.error(`组件错误:`, error);
|
|
170
|
-
}}
|
|
171
|
-
>
|
|
172
|
-
<WrappedComponent {...props} />
|
|
173
|
-
</ErrorBoundary>
|
|
174
|
-
);
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
#### 属性注入插件示例
|
|
181
|
-
|
|
182
|
-
```typescript
|
|
183
|
-
const themePlugin: EnhancedRuntimePlugin = {
|
|
184
|
-
name: 'theme-injector',
|
|
185
|
-
injectProps: (props, context) => {
|
|
186
|
-
return {
|
|
187
|
-
...props,
|
|
188
|
-
theme: {
|
|
189
|
-
mode: 'light',
|
|
190
|
-
primaryColor: '#1890ff'
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
### 插件 API
|
|
198
|
-
|
|
199
|
-
#### EnhancedPluginManager
|
|
200
|
-
|
|
201
|
-
```typescript
|
|
202
|
-
import { getEnhancedPluginManager } from '@ice/mf-runtime';
|
|
203
|
-
|
|
204
|
-
const manager = getEnhancedPluginManager();
|
|
205
|
-
|
|
206
|
-
// 注册增强插件
|
|
207
|
-
manager.register(enhancedPlugin);
|
|
208
|
-
|
|
209
|
-
// 获取插件信息
|
|
210
|
-
const info = manager.getPluginInfo();
|
|
211
|
-
// 返回: [{ name: 'plugin-name', hasWrapper: true, hasInjector: false }]
|
|
212
|
-
|
|
213
|
-
// 移除插件
|
|
214
|
-
manager.removePlugin('plugin-name');
|
|
215
|
-
|
|
216
|
-
// 清空所有插件
|
|
217
|
-
manager.clear();
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
#### React Hook
|
|
221
|
-
|
|
222
|
-
```typescript
|
|
223
|
-
import { useEnhancedPluginManager } from '@ice/mf-runtime';
|
|
224
|
-
|
|
225
|
-
function MyComponent() {
|
|
226
|
-
const enhancedPluginManager = useEnhancedPluginManager();
|
|
227
|
-
|
|
228
|
-
// 动态操作插件
|
|
229
|
-
const handleAddPlugin = () => {
|
|
230
|
-
enhancedPluginManager.register(newEnhancedPlugin);
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
return <div>...</div>;
|
|
234
|
-
}
|
|
235
|
-
```
|
|
236
|
-
|
|
237
17
|
## 使用
|
|
238
18
|
|
|
239
19
|
### 1. 初始化配置
|
package/es2017/RemoteModule.js
CHANGED
|
@@ -6,7 +6,6 @@ import { ErrorBoundary } from 'react-error-boundary';
|
|
|
6
6
|
import { FallBack } from './FallBack';
|
|
7
7
|
import { setFederatedModulePublicPath } from './set-public-path';
|
|
8
8
|
import { getMicroMod } from './mf-global-store';
|
|
9
|
-
import { useEnhancedPluginManager } from './plugin-manager';
|
|
10
9
|
const useMountNode = (mountNodeConfig)=>{
|
|
11
10
|
const [resolvedNode, setResolvedNode] = useState(undefined);
|
|
12
11
|
// 解析各种类型的 mountNode
|
|
@@ -36,7 +35,6 @@ const RemoteModuleInner = ({ module, scope, runtime, publicPath, LoadingComponen
|
|
|
36
35
|
var _microMod, _runtime, _runtime1;
|
|
37
36
|
const microMod = getMicroMod(scope);
|
|
38
37
|
const resolvedMountNode = useMountNode(mountNode);
|
|
39
|
-
const enhancedPluginManager = useEnhancedPluginManager();
|
|
40
38
|
if ((_microMod = microMod) === null || _microMod === void 0 ? void 0 : _microMod.publicPath) {
|
|
41
39
|
setFederatedModulePublicPath(microMod.moduleFederatedName, microMod.publicPath);
|
|
42
40
|
}
|
|
@@ -47,7 +45,6 @@ const RemoteModuleInner = ({ module, scope, runtime, publicPath, LoadingComponen
|
|
|
47
45
|
if (!module || !scope) return null;
|
|
48
46
|
return /*#__PURE__*/ React.lazy(async ()=>{
|
|
49
47
|
var _typedRemoteModule;
|
|
50
|
-
// 使用标准 MF 加载逻辑,MF 插件自动执行
|
|
51
48
|
const remoteModule = await loadRemote(`${scope}/${module}`);
|
|
52
49
|
// 检查是否是来自 runtime plugin 的包装函数(通过标记识别)
|
|
53
50
|
if (typeof remoteModule === 'function' && remoteModule.__ICE_MF_RUNTIME_WRAPPER__) {
|
|
@@ -58,34 +55,25 @@ const RemoteModuleInner = ({ module, scope, runtime, publicPath, LoadingComponen
|
|
|
58
55
|
};
|
|
59
56
|
}
|
|
60
57
|
const typedRemoteModule = remoteModule;
|
|
61
|
-
let BaseComponent;
|
|
62
58
|
if (!((_typedRemoteModule = typedRemoteModule) === null || _typedRemoteModule === void 0 ? void 0 : _typedRemoteModule.default)) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
return {
|
|
60
|
+
default: remoteModule
|
|
61
|
+
};
|
|
66
62
|
}
|
|
67
|
-
// 先应用增强插件的组件包装器
|
|
68
|
-
const WrappedComponent = enhancedPluginManager.wrapComponent(BaseComponent, {
|
|
69
|
-
remoteName: scope,
|
|
70
|
-
moduleName: module,
|
|
71
|
-
props: componentProps || {}
|
|
72
|
-
});
|
|
73
|
-
// 然后处理 runtime 和 mountNode(如果需要)
|
|
74
|
-
let FinalComponent;
|
|
75
63
|
if (runtime) {
|
|
76
64
|
const { react, reactDOM } = runtime;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
65
|
+
return {
|
|
66
|
+
default: FallBack({
|
|
67
|
+
Original: typedRemoteModule.default,
|
|
68
|
+
remoteReact: ()=>react,
|
|
69
|
+
remoteReactDOM: ()=>reactDOM,
|
|
70
|
+
mountNode: resolvedMountNode,
|
|
71
|
+
containerClassName: fallbackContainerClassName
|
|
72
|
+
})
|
|
73
|
+
};
|
|
86
74
|
}
|
|
87
75
|
return {
|
|
88
|
-
default:
|
|
76
|
+
default: typedRemoteModule.default
|
|
89
77
|
};
|
|
90
78
|
});
|
|
91
79
|
}, [
|
|
@@ -94,18 +82,11 @@ const RemoteModuleInner = ({ module, scope, runtime, publicPath, LoadingComponen
|
|
|
94
82
|
(_runtime = runtime) === null || _runtime === void 0 ? void 0 : _runtime.react,
|
|
95
83
|
(_runtime1 = runtime) === null || _runtime1 === void 0 ? void 0 : _runtime1.reactDOM,
|
|
96
84
|
resolvedMountNode,
|
|
97
|
-
fallbackContainerClassName
|
|
98
|
-
enhancedPluginManager,
|
|
99
|
-
componentProps
|
|
85
|
+
fallbackContainerClassName
|
|
100
86
|
]);
|
|
101
87
|
const Loading = LoadingComponent || /*#__PURE__*/ React.createElement("div", null, "Loading...");
|
|
102
88
|
const ErrorFallback = ({ error })=>ErrorComponent || /*#__PURE__*/ React.createElement("div", null, "远程模块加载失败: ", error.message);
|
|
103
89
|
if (!Component) return Loading;
|
|
104
|
-
// 应用增强插件的属性注入
|
|
105
|
-
const injectedProps = enhancedPluginManager.injectProps(componentProps || {}, {
|
|
106
|
-
remoteName: scope,
|
|
107
|
-
moduleName: module
|
|
108
|
-
});
|
|
109
90
|
return /*#__PURE__*/ React.createElement(ErrorBoundary, {
|
|
110
91
|
resetKeys: [
|
|
111
92
|
module,
|
|
@@ -117,8 +98,8 @@ const RemoteModuleInner = ({ module, scope, runtime, publicPath, LoadingComponen
|
|
|
117
98
|
}, /*#__PURE__*/ React.createElement(React.Suspense, {
|
|
118
99
|
fallback: Loading
|
|
119
100
|
}, /*#__PURE__*/ React.createElement(Component, _object_spread({
|
|
120
|
-
ref
|
|
121
|
-
},
|
|
101
|
+
ref: ref
|
|
102
|
+
}, componentProps), children)));
|
|
122
103
|
};
|
|
123
104
|
// 使用 forwardRef 包装组件以支持 ref
|
|
124
105
|
export const RemoteModule = /*#__PURE__*/ forwardRef(RemoteModuleInner);
|
package/es2017/index.d.ts
CHANGED
|
@@ -2,7 +2,5 @@ import type { ExtendedUserOptions, MicroMod } from './types';
|
|
|
2
2
|
export { loadRemote, registerPlugins } from '@module-federation/runtime';
|
|
3
3
|
export * from './FallBack';
|
|
4
4
|
export * from './RemoteModule';
|
|
5
|
-
export * from './types';
|
|
6
|
-
export * from './plugin-manager';
|
|
7
5
|
export declare function init(options: ExtendedUserOptions, microMods?: MicroMod[]): void;
|
|
8
6
|
export declare function initByMicroMods(microMods: MicroMod[], hostName?: string): void;
|
package/es2017/index.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { getBasename } from '@ice/stark-app';
|
|
2
|
-
import { registerPlugins
|
|
2
|
+
import { registerPlugins, init as mfInit } from '@module-federation/runtime';
|
|
3
3
|
import { runtimePlugin } from './runtime-plugin';
|
|
4
4
|
import { initGlobalStore } from './mf-global-store';
|
|
5
5
|
export { loadRemote, registerPlugins } from '@module-federation/runtime';
|
|
6
6
|
export * from './FallBack';
|
|
7
7
|
export * from './RemoteModule';
|
|
8
|
-
export * from './types';
|
|
9
|
-
export * from './plugin-manager';
|
|
10
8
|
export function init(options, microMods) {
|
|
11
9
|
initGlobalStore(options, microMods);
|
|
12
10
|
mfInit(options);
|
|
13
|
-
|
|
11
|
+
registerPlugins([
|
|
14
12
|
runtimePlugin()
|
|
15
13
|
]);
|
|
16
14
|
}
|
package/es2017/runtime-plugin.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { loadShare } from '@module-federation/runtime';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { getExtraInfo, getRemoteInfoFromStore, hasConflict } from './mf-global-store';
|
|
4
3
|
import { FallBack } from './FallBack';
|
|
@@ -10,11 +9,11 @@ const loadRemotePackagedReactAndRender = async (args)=>{
|
|
|
10
9
|
const remoteVersion = remoteInstance ? (_remoteInstance_options = remoteInstance.options) === null || _remoteInstance_options === void 0 ? void 0 : (_remoteInstance_options_shared = _remoteInstance_options.shared) === null || _remoteInstance_options_shared === void 0 ? void 0 : (_remoteInstance_options_shared_reactdom = _remoteInstance_options_shared['react-dom']) === null || _remoteInstance_options_shared_reactdom === void 0 ? void 0 : (_remoteInstance_options_shared_reactdom_ = _remoteInstance_options_shared_reactdom[0]) === null || _remoteInstance_options_shared_reactdom_ === void 0 ? void 0 : _remoteInstance_options_shared_reactdom_.version : false;
|
|
11
10
|
if (remoteVersion && hostVersion) {
|
|
12
11
|
var _sharedOptions_find;
|
|
13
|
-
const remoteReactDOM = await loadShare('react-dom', {
|
|
12
|
+
const remoteReactDOM = await remoteInstance.loadShare('react-dom', {
|
|
14
13
|
resolver: (sharedOptions)=>(_sharedOptions_find = sharedOptions.find((i)=>i.version === remoteVersion)) !== null && _sharedOptions_find !== void 0 ? _sharedOptions_find : sharedOptions[0]
|
|
15
14
|
});
|
|
16
15
|
var _sharedOptions_find1;
|
|
17
|
-
const remoteReact = await loadShare('react', {
|
|
16
|
+
const remoteReact = await remoteInstance.loadShare('react', {
|
|
18
17
|
resolver: (sharedOptions)=>(_sharedOptions_find1 = sharedOptions.find((i)=>i.version === remoteVersion)) !== null && _sharedOptions_find1 !== void 0 ? _sharedOptions_find1 : sharedOptions[0]
|
|
19
18
|
});
|
|
20
19
|
if (!remoteReact || !remoteReactDOM) {
|
|
@@ -54,6 +53,9 @@ export const runtimePlugin = ()=>({
|
|
|
54
53
|
var _args_origin_options_shared_reactdom_, _args_origin_options_shared_reactdom, _args_origin_options_shared, _args_origin_options, _extraInfo;
|
|
55
54
|
const hostName = args.origin.name;
|
|
56
55
|
const remoteName = args.remote.name;
|
|
56
|
+
console.error(__webpack_init_sharing__);
|
|
57
|
+
console.error(__webpack_share_scopes__);
|
|
58
|
+
window.a = __webpack_share_scopes__;
|
|
57
59
|
const hostVersion = ((_args_origin_options = args.origin.options) === null || _args_origin_options === void 0 ? void 0 : (_args_origin_options_shared = _args_origin_options.shared) === null || _args_origin_options_shared === void 0 ? void 0 : (_args_origin_options_shared_reactdom = _args_origin_options_shared['react-dom']) === null || _args_origin_options_shared_reactdom === void 0 ? void 0 : (_args_origin_options_shared_reactdom_ = _args_origin_options_shared_reactdom[0]) === null || _args_origin_options_shared_reactdom_ === void 0 ? void 0 : _args_origin_options_shared_reactdom_.version) || React.version;
|
|
58
60
|
const extraInfo = getExtraInfo(hostName, remoteName);
|
|
59
61
|
if ((_extraInfo = extraInfo) === null || _extraInfo === void 0 ? void 0 : _extraInfo.external) {
|
package/es2017/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { UserOptions } from '@module-federation/runtime-core';
|
|
2
2
|
import type { Remote } from '@module-federation/runtime-core/dist/src/types';
|
|
3
|
-
import * as React from 'react';
|
|
4
3
|
export interface ExtraInfo {
|
|
5
4
|
external?: Record<string, string>;
|
|
6
5
|
legacy?: boolean;
|
|
@@ -19,29 +18,3 @@ export interface MicroMod {
|
|
|
19
18
|
moduleFederatedName: string;
|
|
20
19
|
extraInfo?: ExtraInfo;
|
|
21
20
|
}
|
|
22
|
-
export interface FederationRuntimePlugin {
|
|
23
|
-
name: string;
|
|
24
|
-
afterResolve?: (args: any) => any;
|
|
25
|
-
onLoad?: (args: any) => any;
|
|
26
|
-
beforeRequest?: (args: any) => any;
|
|
27
|
-
}
|
|
28
|
-
export interface WrapperContext {
|
|
29
|
-
remoteName: string;
|
|
30
|
-
moduleName: string;
|
|
31
|
-
props: Record<string, any>;
|
|
32
|
-
}
|
|
33
|
-
export interface InjectionContext {
|
|
34
|
-
remoteName: string;
|
|
35
|
-
moduleName: string;
|
|
36
|
-
}
|
|
37
|
-
export interface ComponentWrapper {
|
|
38
|
-
(WrappedComponent: React.ComponentType<any>, context: WrapperContext): React.ComponentType<any>;
|
|
39
|
-
}
|
|
40
|
-
export interface PropInjector {
|
|
41
|
-
(props: Record<string, any>, context: InjectionContext): Record<string, any>;
|
|
42
|
-
}
|
|
43
|
-
export interface EnhancedRuntimePlugin {
|
|
44
|
-
name: string;
|
|
45
|
-
wrapComponent?: ComponentWrapper;
|
|
46
|
-
injectProps?: PropInjector;
|
|
47
|
-
}
|
package/es2017/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// 不再需要联合类型,两种插件分开管理
|
|
1
|
+
export { };
|
package/esm/RemoteModule.js
CHANGED
|
@@ -10,7 +10,6 @@ import { ErrorBoundary } from "react-error-boundary";
|
|
|
10
10
|
import { FallBack } from "./FallBack";
|
|
11
11
|
import { setFederatedModulePublicPath } from "./set-public-path";
|
|
12
12
|
import { getMicroMod } from "./mf-global-store";
|
|
13
|
-
import { useEnhancedPluginManager } from "./plugin-manager";
|
|
14
13
|
var useMountNode = function(mountNodeConfig) {
|
|
15
14
|
var _useState = _sliced_to_array(useState(undefined), 2), resolvedNode = _useState[0], setResolvedNode = _useState[1];
|
|
16
15
|
// 解析各种类型的 mountNode
|
|
@@ -41,7 +40,6 @@ var RemoteModuleInner = function(param, ref) {
|
|
|
41
40
|
var _microMod, _runtime, _runtime1;
|
|
42
41
|
var microMod = getMicroMod(scope);
|
|
43
42
|
var resolvedMountNode = useMountNode(mountNode);
|
|
44
|
-
var enhancedPluginManager = useEnhancedPluginManager();
|
|
45
43
|
if ((_microMod = microMod) === null || _microMod === void 0 ? void 0 : _microMod.publicPath) {
|
|
46
44
|
setFederatedModulePublicPath(microMod.moduleFederatedName, microMod.publicPath);
|
|
47
45
|
}
|
|
@@ -51,7 +49,7 @@ var RemoteModuleInner = function(param, ref) {
|
|
|
51
49
|
var Component = useMemo(function() {
|
|
52
50
|
if (!module || !scope) return null;
|
|
53
51
|
return /*#__PURE__*/ React.lazy(/*#__PURE__*/ _async_to_generator(function() {
|
|
54
|
-
var _typedRemoteModule, remoteModule, ComponentFromPlugin, typedRemoteModule,
|
|
52
|
+
var _typedRemoteModule, remoteModule, ComponentFromPlugin, typedRemoteModule, react, reactDOM;
|
|
55
53
|
return _ts_generator(this, function(_state) {
|
|
56
54
|
switch(_state.label){
|
|
57
55
|
case 0:
|
|
@@ -73,35 +71,36 @@ var RemoteModuleInner = function(param, ref) {
|
|
|
73
71
|
}
|
|
74
72
|
typedRemoteModule = remoteModule;
|
|
75
73
|
if (!((_typedRemoteModule = typedRemoteModule) === null || _typedRemoteModule === void 0 ? void 0 : _typedRemoteModule.default)) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
return [
|
|
75
|
+
2,
|
|
76
|
+
{
|
|
77
|
+
default: remoteModule
|
|
78
|
+
}
|
|
79
|
+
];
|
|
79
80
|
}
|
|
80
|
-
WrappedComponent = enhancedPluginManager.wrapComponent(BaseComponent, {
|
|
81
|
-
remoteName: scope,
|
|
82
|
-
moduleName: module,
|
|
83
|
-
props: componentProps || {}
|
|
84
|
-
});
|
|
85
81
|
if (runtime) {
|
|
86
82
|
react = runtime.react, reactDOM = runtime.reactDOM;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
return [
|
|
84
|
+
2,
|
|
85
|
+
{
|
|
86
|
+
default: FallBack({
|
|
87
|
+
Original: typedRemoteModule.default,
|
|
88
|
+
remoteReact: function() {
|
|
89
|
+
return react;
|
|
90
|
+
},
|
|
91
|
+
remoteReactDOM: function() {
|
|
92
|
+
return reactDOM;
|
|
93
|
+
},
|
|
94
|
+
mountNode: resolvedMountNode,
|
|
95
|
+
containerClassName: fallbackContainerClassName
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
];
|
|
100
99
|
}
|
|
101
100
|
return [
|
|
102
101
|
2,
|
|
103
102
|
{
|
|
104
|
-
default:
|
|
103
|
+
default: typedRemoteModule.default
|
|
105
104
|
}
|
|
106
105
|
];
|
|
107
106
|
}
|
|
@@ -113,9 +112,7 @@ var RemoteModuleInner = function(param, ref) {
|
|
|
113
112
|
(_runtime = runtime) === null || _runtime === void 0 ? void 0 : _runtime.react,
|
|
114
113
|
(_runtime1 = runtime) === null || _runtime1 === void 0 ? void 0 : _runtime1.reactDOM,
|
|
115
114
|
resolvedMountNode,
|
|
116
|
-
fallbackContainerClassName
|
|
117
|
-
enhancedPluginManager,
|
|
118
|
-
componentProps
|
|
115
|
+
fallbackContainerClassName
|
|
119
116
|
]);
|
|
120
117
|
var Loading = LoadingComponent || /*#__PURE__*/ React.createElement("div", null, "Loading...");
|
|
121
118
|
var ErrorFallback = function(param) {
|
|
@@ -123,11 +120,6 @@ var RemoteModuleInner = function(param, ref) {
|
|
|
123
120
|
return ErrorComponent || /*#__PURE__*/ React.createElement("div", null, "远程模块加载失败: ", error.message);
|
|
124
121
|
};
|
|
125
122
|
if (!Component) return Loading;
|
|
126
|
-
// 应用增强插件的属性注入
|
|
127
|
-
var injectedProps = enhancedPluginManager.injectProps(componentProps || {}, {
|
|
128
|
-
remoteName: scope,
|
|
129
|
-
moduleName: module
|
|
130
|
-
});
|
|
131
123
|
return /*#__PURE__*/ React.createElement(ErrorBoundary, {
|
|
132
124
|
resetKeys: [
|
|
133
125
|
module,
|
|
@@ -140,7 +132,7 @@ var RemoteModuleInner = function(param, ref) {
|
|
|
140
132
|
fallback: Loading
|
|
141
133
|
}, /*#__PURE__*/ React.createElement(Component, _object_spread({
|
|
142
134
|
ref: ref
|
|
143
|
-
},
|
|
135
|
+
}, componentProps), children)));
|
|
144
136
|
};
|
|
145
137
|
// 使用 forwardRef 包装组件以支持 ref
|
|
146
138
|
export var RemoteModule = /*#__PURE__*/ forwardRef(RemoteModuleInner);
|
package/esm/index.d.ts
CHANGED
|
@@ -2,7 +2,5 @@ import type { ExtendedUserOptions, MicroMod } from './types';
|
|
|
2
2
|
export { loadRemote, registerPlugins } from '@module-federation/runtime';
|
|
3
3
|
export * from './FallBack';
|
|
4
4
|
export * from './RemoteModule';
|
|
5
|
-
export * from './types';
|
|
6
|
-
export * from './plugin-manager';
|
|
7
5
|
export declare function init(options: ExtendedUserOptions, microMods?: MicroMod[]): void;
|
|
8
6
|
export declare function initByMicroMods(microMods: MicroMod[], hostName?: string): void;
|
package/esm/index.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { getBasename } from "@ice/stark-app";
|
|
2
|
-
import { registerPlugins
|
|
2
|
+
import { registerPlugins, init as mfInit } from "@module-federation/runtime";
|
|
3
3
|
import { runtimePlugin } from "./runtime-plugin";
|
|
4
4
|
import { initGlobalStore } from "./mf-global-store";
|
|
5
5
|
export { loadRemote, registerPlugins } from "@module-federation/runtime";
|
|
6
6
|
export * from "./FallBack";
|
|
7
7
|
export * from "./RemoteModule";
|
|
8
|
-
export * from "./types";
|
|
9
|
-
export * from "./plugin-manager";
|
|
10
8
|
export function init(options, microMods) {
|
|
11
9
|
initGlobalStore(options, microMods);
|
|
12
10
|
mfInit(options);
|
|
13
|
-
|
|
11
|
+
registerPlugins([
|
|
14
12
|
runtimePlugin()
|
|
15
13
|
]);
|
|
16
14
|
}
|
package/esm/runtime-plugin.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
-
import { loadShare } from "@module-federation/runtime";
|
|
4
3
|
import * as React from "react";
|
|
5
4
|
import { getExtraInfo, getRemoteInfoFromStore, hasConflict } from "./mf-global-store";
|
|
6
5
|
import { FallBack } from "./FallBack";
|
|
@@ -22,7 +21,7 @@ var loadRemotePackagedReactAndRender = function() {
|
|
|
22
21
|
];
|
|
23
22
|
return [
|
|
24
23
|
4,
|
|
25
|
-
loadShare("react-dom", {
|
|
24
|
+
remoteInstance.loadShare("react-dom", {
|
|
26
25
|
resolver: function(sharedOptions) {
|
|
27
26
|
return (_sharedOptions_find = sharedOptions.find(function(i) {
|
|
28
27
|
return i.version === remoteVersion;
|
|
@@ -34,7 +33,7 @@ var loadRemotePackagedReactAndRender = function() {
|
|
|
34
33
|
remoteReactDOM = _state.sent();
|
|
35
34
|
return [
|
|
36
35
|
4,
|
|
37
|
-
loadShare("react", {
|
|
36
|
+
remoteInstance.loadShare("react", {
|
|
38
37
|
resolver: function(sharedOptions) {
|
|
39
38
|
return (_sharedOptions_find1 = sharedOptions.find(function(i) {
|
|
40
39
|
return i.version === remoteVersion;
|
|
@@ -106,6 +105,9 @@ export var runtimePlugin = function() {
|
|
|
106
105
|
case 0:
|
|
107
106
|
hostName = args.origin.name;
|
|
108
107
|
remoteName = args.remote.name;
|
|
108
|
+
console.error(__webpack_init_sharing__);
|
|
109
|
+
console.error(__webpack_share_scopes__);
|
|
110
|
+
window.a = __webpack_share_scopes__;
|
|
109
111
|
hostVersion = ((_args_origin_options = args.origin.options) === null || _args_origin_options === void 0 ? void 0 : (_args_origin_options_shared = _args_origin_options.shared) === null || _args_origin_options_shared === void 0 ? void 0 : (_args_origin_options_shared_reactdom = _args_origin_options_shared["react-dom"]) === null || _args_origin_options_shared_reactdom === void 0 ? void 0 : (_args_origin_options_shared_reactdom_ = _args_origin_options_shared_reactdom[0]) === null || _args_origin_options_shared_reactdom_ === void 0 ? void 0 : _args_origin_options_shared_reactdom_.version) || React.version;
|
|
110
112
|
extraInfo = getExtraInfo(hostName, remoteName);
|
|
111
113
|
if ((_extraInfo = extraInfo) === null || _extraInfo === void 0 ? void 0 : _extraInfo.external) {
|
package/esm/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { UserOptions } from '@module-federation/runtime-core';
|
|
2
2
|
import type { Remote } from '@module-federation/runtime-core/dist/src/types';
|
|
3
|
-
import * as React from 'react';
|
|
4
3
|
export interface ExtraInfo {
|
|
5
4
|
external?: Record<string, string>;
|
|
6
5
|
legacy?: boolean;
|
|
@@ -19,29 +18,3 @@ export interface MicroMod {
|
|
|
19
18
|
moduleFederatedName: string;
|
|
20
19
|
extraInfo?: ExtraInfo;
|
|
21
20
|
}
|
|
22
|
-
export interface FederationRuntimePlugin {
|
|
23
|
-
name: string;
|
|
24
|
-
afterResolve?: (args: any) => any;
|
|
25
|
-
onLoad?: (args: any) => any;
|
|
26
|
-
beforeRequest?: (args: any) => any;
|
|
27
|
-
}
|
|
28
|
-
export interface WrapperContext {
|
|
29
|
-
remoteName: string;
|
|
30
|
-
moduleName: string;
|
|
31
|
-
props: Record<string, any>;
|
|
32
|
-
}
|
|
33
|
-
export interface InjectionContext {
|
|
34
|
-
remoteName: string;
|
|
35
|
-
moduleName: string;
|
|
36
|
-
}
|
|
37
|
-
export interface ComponentWrapper {
|
|
38
|
-
(WrappedComponent: React.ComponentType<any>, context: WrapperContext): React.ComponentType<any>;
|
|
39
|
-
}
|
|
40
|
-
export interface PropInjector {
|
|
41
|
-
(props: Record<string, any>, context: InjectionContext): Record<string, any>;
|
|
42
|
-
}
|
|
43
|
-
export interface EnhancedRuntimePlugin {
|
|
44
|
-
name: string;
|
|
45
|
-
wrapComponent?: ComponentWrapper;
|
|
46
|
-
injectProps?: PropInjector;
|
|
47
|
-
}
|
package/esm/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// 不再需要联合类型,两种插件分开管理
|
|
1
|
+
export { };
|