@umijs/plugins 4.6.28 → 4.6.30

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 CHANGED
@@ -46,7 +46,8 @@ function mf(api) {
46
46
  name: zod.string(),
47
47
  entry: zod.string().optional(),
48
48
  entries: zod.object({}).optional(),
49
- keyResolver: zod.string().optional()
49
+ keyResolver: zod.string().optional(),
50
+ runtimeEntryPath: zod.object({}).optional()
50
51
  })
51
52
  ),
52
53
  shared: zod.record(zod.any()),
@@ -187,16 +188,41 @@ function mf(api) {
187
188
  }
188
189
  function formatRemote(remote) {
189
190
  if (remote.entry) {
190
- return `${remote.name}@${remote.entry}`;
191
+ if (!remote.runtimeEntryPath) {
192
+ return `${remote.name}@${remote.entry}`;
193
+ }
194
+ return `promise new Promise(resolve => {
195
+
196
+ const script = document.createElement('script');
197
+ script.src = window["mf_${remote.name}EntryPath"];
198
+ script.onload = () => {
199
+ // the injected script has loaded and is available on window
200
+ // we can now resolve this Promise
201
+ const proxy = {
202
+ get: (request) => window.${remote.name}.get(request),
203
+ init: (arg) => {
204
+ try {
205
+ return window.${remote.name}.init(arg);
206
+ } catch(e) {
207
+ console.log('remote container already initialized');
208
+ }
209
+ }
210
+ }
211
+ resolve(proxy);
212
+ }
213
+ // inject this script with the src set to the versioned remoteEntry.js
214
+ document.head.appendChild(script);
215
+ })
216
+ `;
191
217
  }
192
218
  if (remote.entries && remote.keyResolver) {
193
219
  const dynamicUrl = `promise new Promise(resolve => {
194
220
  const entries = ${JSON.stringify(remote.entries)};
195
221
  const key = ${remote.keyResolver};
196
222
 
197
- const remoteUrlWithVersion = entries[key];
198
- const script = document.createElement('script')
199
- script.src = remoteUrlWithVersion
223
+ const remoteUrlWithVersion = ${remote.runtimeEntryPath ? `window["mf_${remote.name}EntryPath"]` : "entries[key]"};
224
+ const script = document.createElement('script');
225
+ script.src = remoteUrlWithVersion;
200
226
  script.onload = () => {
201
227
  // the injected script has loaded and is available on window
202
228
  // we can now resolve this Promise
@@ -204,13 +230,13 @@ function mf(api) {
204
230
  get: (request) => window.${remote.name}.get(request),
205
231
  init: (arg) => {
206
232
  try {
207
- return window.${remote.name}.init(arg)
233
+ return window.${remote.name}.init(arg);
208
234
  } catch(e) {
209
- console.log('remote container already initialized')
235
+ console.log('remote container already initialized');
210
236
  }
211
237
  }
212
238
  }
213
- resolve(proxy)
239
+ resolve(proxy);
214
240
  }
215
241
  // inject this script with the src set to the versioned remoteEntry.js
216
242
  document.head.appendChild(script);
@@ -2,12 +2,14 @@ declare type SimpleRemote = {
2
2
  entry: string;
3
3
  name: string;
4
4
  aliasName?: string;
5
+ runtimeEntryPath?: object;
5
6
  };
6
7
  declare type RemoteEntries = {
7
8
  name: string;
8
9
  entries: object;
9
10
  keyResolver: string;
10
11
  aliasName?: string;
12
+ runtimeEntryPath?: object;
11
13
  };
12
14
  declare type Remote = SimpleRemote | RemoteEntries;
13
15
  export declare function toRemotesCodeString(remotes: Remote[]): string;
@@ -36,15 +36,15 @@ function toRemotesCodeString(remotes) {
36
36
  if (isSimpleRemote(r)) {
37
37
  res.push(`${aliasName}: {
38
38
  aliasName: "${aliasName}",
39
- remoteName: "${remoteName}",
40
- entry: "${r.entry}"
39
+ remoteName: "${remoteName}",
40
+ entry: ${r.runtimeEntryPath ? `window["mf_${r.name}EntryPath"]` : `"${r.entry}"`}
41
41
  }`);
42
42
  }
43
43
  if (isRemoteEntries(r)) {
44
44
  res.push(`${aliasName}: {
45
45
  aliasName: "${aliasName}",
46
- remoteName: "${remoteName}",
47
- entry: (${JSON.stringify(r.entries)})[${r.keyResolver}]
46
+ remoteName: "${remoteName}",
47
+ entry: ${r.runtimeEntryPath ? `window["mf_${r.name}EntryPath"]` : `(${JSON.stringify(r.entries)})[${r.keyResolver}]`}
48
48
  }`);
49
49
  }
50
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.6.28",
3
+ "version": "4.6.30",
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",
@@ -45,12 +45,12 @@
45
45
  "styled-components": "6.1.1",
46
46
  "tslib": "^2",
47
47
  "warning": "^4.0.3",
48
- "@umijs/bundler-utils": "4.6.28",
48
+ "@umijs/bundler-utils": "4.6.30",
49
49
  "@umijs/valtio": "1.0.4"
50
50
  },
51
51
  "devDependencies": {
52
52
  "antd": "^4.24.1",
53
- "umi": "4.6.28"
53
+ "umi": "4.6.30"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"