@umijs/plugins 4.0.0-canary.20220824.1 → 4.0.0-canary.20220826.1
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/dist/mf.js +1 -1
- package/package.json +3 -3
- package/tpls/mf-runtime.ts.tpl +39 -2
package/dist/mf.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20220826.1",
|
|
4
4
|
"description": "@umijs/plugins",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@ant-design/antd-theme-variable": "^1.0.0",
|
|
28
28
|
"@ant-design/icons": "^4.7.0",
|
|
29
29
|
"@ant-design/pro-layout": "^7.0.1-beta.28",
|
|
30
|
-
"@umijs/bundler-utils": "4.0.0-canary.
|
|
30
|
+
"@umijs/bundler-utils": "4.0.0-canary.20220826.1",
|
|
31
31
|
"antd-dayjs-webpack-plugin": "^1.0.6",
|
|
32
32
|
"axios": "^0.27.2",
|
|
33
33
|
"babel-plugin-import": "^1.13.5",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"warning": "^4.0.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"umi": "4.0.0-canary.
|
|
49
|
+
"umi": "4.0.0-canary.20220826.1"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
package/tpls/mf-runtime.ts.tpl
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { lazy, Suspense } from 'react'
|
|
2
|
+
import type { Component, ReactNode } from 'react'
|
|
1
3
|
const remotes = {
|
|
2
4
|
{{{ remoteCodeString }}}
|
|
3
5
|
};
|
|
4
6
|
const scriptLoadedMap: Record<string, Promise<void> | 0 | undefined> = {};
|
|
5
7
|
|
|
6
|
-
type MFModuleImportRequest = { entry: string
|
|
7
|
-
type MFModuleRegisterRequest = { entry: string
|
|
8
|
+
type MFModuleImportRequest = { entry: string; remoteName: string; moduleName: string; }
|
|
9
|
+
type MFModuleRegisterRequest = { entry: string; remoteName: string; aliasName?:string; }
|
|
8
10
|
|
|
9
11
|
export async function rawMfImport(opts: MFModuleImportRequest) {
|
|
10
12
|
await loadRemoteScriptWithCache(opts.remoteName, opts.entry);
|
|
@@ -110,3 +112,38 @@ async function loadRemoteScriptWithCache(remoteName:string, url: string): Promis
|
|
|
110
112
|
await p;
|
|
111
113
|
}
|
|
112
114
|
}
|
|
115
|
+
|
|
116
|
+
type SafeRemoteComponentOpts ={
|
|
117
|
+
moduleSpecifier:string;
|
|
118
|
+
fallbackComponent: ComponentType<any>;
|
|
119
|
+
loadingElement: ReactNode
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function safeRemoteComponent<T extends ComponentType<any>>(opts: SafeRemoteComponentOpts): T {
|
|
123
|
+
const Lazy = lazy<T>(()=>safeMfImport(opts.moduleSpecifier, { default: opts.fallbackComponent }));
|
|
124
|
+
return (props)=> (<Suspense fallback={opts.loadingElement}>
|
|
125
|
+
<Lazy {...props} />
|
|
126
|
+
</Suspense>)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
type RawRemoteComponentOpts ={
|
|
130
|
+
mfConfig:{
|
|
131
|
+
entry:string;
|
|
132
|
+
remoteName: string;
|
|
133
|
+
moduleName: string;
|
|
134
|
+
};
|
|
135
|
+
fallbackComponent: ComponentType<any>;
|
|
136
|
+
loadingElement: ReactNode;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function safeRemoteComponentWithMfConfig<T extends ComponentType<any>>(opts: RawRemoteComponentOpts): T {
|
|
140
|
+
const Lazy = lazy<T>(()=>{
|
|
141
|
+
return rawMfImport(opts.mfConfig)
|
|
142
|
+
.catch(()=>{
|
|
143
|
+
return { default: opts.fallbackComponent };
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
return (props)=> (<Suspense fallback={opts.loadingElement}>
|
|
147
|
+
<Lazy {...props} />
|
|
148
|
+
</Suspense>)
|
|
149
|
+
}
|