@ice/mf-runtime 1.0.3 → 1.0.4-beta.0
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/es2017/RemoteModule.js +2 -6
- package/es2017/index.js +8 -2
- package/es2017/mf-global-store.js +7 -0
- package/esm/RemoteModule.js +2 -6
- package/esm/index.js +8 -2
- package/esm/mf-global-store.js +7 -0
- package/package.json +1 -1
package/es2017/RemoteModule.js
CHANGED
|
@@ -5,7 +5,6 @@ import { useMemo, useState, useLayoutEffect, forwardRef } from 'react';
|
|
|
5
5
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
6
6
|
import { FallBack } from './FallBack';
|
|
7
7
|
import { setFederatedModulePublicPath } from './set-public-path';
|
|
8
|
-
import { getMicroMod } from './mf-global-store';
|
|
9
8
|
const useMountNode = (mountNodeConfig)=>{
|
|
10
9
|
const [resolvedNode, setResolvedNode] = useState(undefined);
|
|
11
10
|
// 解析各种类型的 mountNode
|
|
@@ -32,12 +31,9 @@ const useMountNode = (mountNodeConfig)=>{
|
|
|
32
31
|
return resolvedNode;
|
|
33
32
|
};
|
|
34
33
|
const RemoteModuleInner = ({ module, scope, runtime, publicPath, LoadingComponent, ErrorComponent, onError, componentProps = {}, children = null, mountNode, fallbackContainerClassName }, ref)=>{
|
|
35
|
-
var
|
|
36
|
-
const microMod = getMicroMod(scope);
|
|
34
|
+
var _runtime, _runtime1;
|
|
37
35
|
const resolvedMountNode = useMountNode(mountNode);
|
|
38
|
-
|
|
39
|
-
setFederatedModulePublicPath(microMod.moduleFederatedName, microMod.publicPath);
|
|
40
|
-
}
|
|
36
|
+
// 运行时传入的 publicPath 优先级更高,会覆盖 initGlobalStore 中设置的值
|
|
41
37
|
if (publicPath) {
|
|
42
38
|
setFederatedModulePublicPath(scope, publicPath);
|
|
43
39
|
}
|
package/es2017/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getBasename } from '@ice/stark-app';
|
|
2
1
|
import { registerPlugins, init as mfInit } from '@module-federation/runtime';
|
|
3
2
|
import { runtimePlugin } from './runtime-plugin';
|
|
4
3
|
import { initGlobalStore } from './mf-global-store';
|
|
@@ -12,6 +11,13 @@ export function init(options, microMods) {
|
|
|
12
11
|
runtimePlugin()
|
|
13
12
|
]);
|
|
14
13
|
}
|
|
14
|
+
// 获取当前 URL 的 basename(路径)
|
|
15
|
+
function getBasename() {
|
|
16
|
+
// 使用 window.location.pathname 获取当前 URL 的真实路径
|
|
17
|
+
const pathname = window.location.pathname;
|
|
18
|
+
// 移除开头的 '/' 和结尾的 '/',并将中划线转换为下划线
|
|
19
|
+
return (pathname.replace(/^\/|\/$/g, '') || 'root').replace(/-/g, '_');
|
|
20
|
+
}
|
|
15
21
|
// 需要一个稳定的,微应用唯一的 ID
|
|
16
22
|
function generateUniqueId() {
|
|
17
23
|
const prefix = 'ice_standard';
|
|
@@ -34,6 +40,6 @@ export function initByMicroMods(microMods, hostName) {
|
|
|
34
40
|
});
|
|
35
41
|
init({
|
|
36
42
|
remotes,
|
|
37
|
-
name:
|
|
43
|
+
name: generateUniqueId() || hostName
|
|
38
44
|
}, microMods);
|
|
39
45
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setFederatedModulePublicPath } from './set-public-path';
|
|
1
2
|
export function getCurrentModuleNames() {
|
|
2
3
|
var _window___MF_GLOBAL_STORE__;
|
|
3
4
|
return ((_window___MF_GLOBAL_STORE__ = window.__MF_GLOBAL_STORE__) === null || _window___MF_GLOBAL_STORE__ === void 0 ? void 0 : _window___MF_GLOBAL_STORE__.currentModuleNames) || [];
|
|
@@ -38,6 +39,12 @@ export function initGlobalStore(options, microMods) {
|
|
|
38
39
|
window.__MF_GLOBAL_STORE__.microMods = new Map();
|
|
39
40
|
}
|
|
40
41
|
window.__MF_GLOBAL_STORE__.microMods.set(options.name, microMods);
|
|
42
|
+
// 批量设置 microMods 的 publicPath
|
|
43
|
+
microMods.forEach((microMod)=>{
|
|
44
|
+
if (microMod.publicPath && microMod.moduleFederatedName) {
|
|
45
|
+
setFederatedModulePublicPath(microMod.moduleFederatedName, microMod.publicPath);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
41
48
|
}
|
|
42
49
|
const store = window.__MF_GLOBAL_STORE__;
|
|
43
50
|
if (!window.getCurrentIceMicroMods) {
|
package/esm/RemoteModule.js
CHANGED
|
@@ -9,7 +9,6 @@ import { useMemo, useState, useLayoutEffect, forwardRef } from "react";
|
|
|
9
9
|
import { ErrorBoundary } from "react-error-boundary";
|
|
10
10
|
import { FallBack } from "./FallBack";
|
|
11
11
|
import { setFederatedModulePublicPath } from "./set-public-path";
|
|
12
|
-
import { getMicroMod } from "./mf-global-store";
|
|
13
12
|
var useMountNode = function(mountNodeConfig) {
|
|
14
13
|
var _useState = _sliced_to_array(useState(undefined), 2), resolvedNode = _useState[0], setResolvedNode = _useState[1];
|
|
15
14
|
// 解析各种类型的 mountNode
|
|
@@ -37,12 +36,9 @@ var useMountNode = function(mountNodeConfig) {
|
|
|
37
36
|
};
|
|
38
37
|
var RemoteModuleInner = function(param, ref) {
|
|
39
38
|
var module = param.module, scope = param.scope, runtime = param.runtime, publicPath = param.publicPath, LoadingComponent = param.LoadingComponent, ErrorComponent = param.ErrorComponent, onError = param.onError, _param_componentProps = param.componentProps, componentProps = _param_componentProps === void 0 ? {} : _param_componentProps, _param_children = param.children, children = _param_children === void 0 ? null : _param_children, mountNode = param.mountNode, fallbackContainerClassName = param.fallbackContainerClassName;
|
|
40
|
-
var
|
|
41
|
-
var microMod = getMicroMod(scope);
|
|
39
|
+
var _runtime, _runtime1;
|
|
42
40
|
var resolvedMountNode = useMountNode(mountNode);
|
|
43
|
-
|
|
44
|
-
setFederatedModulePublicPath(microMod.moduleFederatedName, microMod.publicPath);
|
|
45
|
-
}
|
|
41
|
+
// 运行时传入的 publicPath 优先级更高,会覆盖 initGlobalStore 中设置的值
|
|
46
42
|
if (publicPath) {
|
|
47
43
|
setFederatedModulePublicPath(scope, publicPath);
|
|
48
44
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getBasename } from "@ice/stark-app";
|
|
2
1
|
import { registerPlugins, init as mfInit } from "@module-federation/runtime";
|
|
3
2
|
import { runtimePlugin } from "./runtime-plugin";
|
|
4
3
|
import { initGlobalStore } from "./mf-global-store";
|
|
@@ -12,6 +11,13 @@ export function init(options, microMods) {
|
|
|
12
11
|
runtimePlugin()
|
|
13
12
|
]);
|
|
14
13
|
}
|
|
14
|
+
// 获取当前 URL 的 basename(路径)
|
|
15
|
+
function getBasename() {
|
|
16
|
+
// 使用 window.location.pathname 获取当前 URL 的真实路径
|
|
17
|
+
var pathname = window.location.pathname;
|
|
18
|
+
// 移除开头的 '/' 和结尾的 '/',并将中划线转换为下划线
|
|
19
|
+
return (pathname.replace(/^\/|\/$/g, "") || "root").replace(/-/g, "_");
|
|
20
|
+
}
|
|
15
21
|
// 需要一个稳定的,微应用唯一的 ID
|
|
16
22
|
function generateUniqueId() {
|
|
17
23
|
var prefix = "ice_standard";
|
|
@@ -34,6 +40,6 @@ export function initByMicroMods(microMods, hostName) {
|
|
|
34
40
|
});
|
|
35
41
|
init({
|
|
36
42
|
remotes: remotes,
|
|
37
|
-
name:
|
|
43
|
+
name: generateUniqueId() || hostName
|
|
38
44
|
}, microMods);
|
|
39
45
|
}
|
package/esm/mf-global-store.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
2
2
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
+
import { setFederatedModulePublicPath } from "./set-public-path";
|
|
3
4
|
export function getCurrentModuleNames() {
|
|
4
5
|
var _window___MF_GLOBAL_STORE__;
|
|
5
6
|
return ((_window___MF_GLOBAL_STORE__ = window.__MF_GLOBAL_STORE__) === null || _window___MF_GLOBAL_STORE__ === void 0 ? void 0 : _window___MF_GLOBAL_STORE__.currentModuleNames) || [];
|
|
@@ -59,6 +60,12 @@ export function initGlobalStore(options, microMods) {
|
|
|
59
60
|
window.__MF_GLOBAL_STORE__.microMods = new Map();
|
|
60
61
|
}
|
|
61
62
|
window.__MF_GLOBAL_STORE__.microMods.set(options.name, microMods);
|
|
63
|
+
// 批量设置 microMods 的 publicPath
|
|
64
|
+
microMods.forEach(function(microMod) {
|
|
65
|
+
if (microMod.publicPath && microMod.moduleFederatedName) {
|
|
66
|
+
setFederatedModulePublicPath(microMod.moduleFederatedName, microMod.publicPath);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
62
69
|
}
|
|
63
70
|
var store = window.__MF_GLOBAL_STORE__;
|
|
64
71
|
if (!window.getCurrentIceMicroMods) {
|