Skip to content

Commit 19bb05d

Browse files
authored
feat: dev mode manifest.json (#127)
1 parent 8ed7256 commit 19bb05d

File tree

1 file changed

+7
-63
lines changed

1 file changed

+7
-63
lines changed

src/plugins/pluginMFManifest.ts

Lines changed: 7 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const Manifest = (): Plugin[] => {
4343
res.setHeader('Access-Control-Allow-Origin', '*');
4444
res.end(
4545
JSON.stringify({
46+
...generateMFManifest({}),
4647
id: name,
4748
name: name,
4849
metaData: {
@@ -64,60 +65,6 @@ const Manifest = (): Plugin[] => {
6465
pluginVersion: '0.2.5',
6566
publicPath,
6667
},
67-
shared: Array.from(getUsedShares()).map((shareKey) => {
68-
const shareItem = getNormalizeShareItem(shareKey);
69-
70-
return {
71-
id: `${name}:${shareKey}`,
72-
name: shareKey,
73-
version: shareItem.version,
74-
requiredVersion: shareItem.shareConfig.requiredVersion,
75-
assets: {
76-
js: {
77-
async: [],
78-
sync: [],
79-
},
80-
css: {
81-
async: [],
82-
sync: [],
83-
},
84-
},
85-
};
86-
}),
87-
remotes: (function () {
88-
const remotes = [] as any;
89-
const usedRemotesMap = getUsedRemotesMap();
90-
Object.keys(usedRemotesMap).forEach((remoteKey) => {
91-
const usedModules = Array.from(usedRemotesMap[remoteKey]);
92-
usedModules.forEach((moduleKey) => {
93-
remotes.push({
94-
federationContainerName: mfOptions.remotes[remoteKey].entry,
95-
moduleName: moduleKey.replace(remoteKey, '').replace('/', ''),
96-
alias: remoteKey,
97-
entry: '*',
98-
});
99-
});
100-
});
101-
return remotes;
102-
})(),
103-
exposes: Object.keys(mfOptions.exposes).map((key) => {
104-
const formatKey = key.replace('./', '');
105-
return {
106-
id: name + ':' + formatKey,
107-
name: formatKey,
108-
assets: {
109-
js: {
110-
async: [],
111-
sync: [],
112-
},
113-
css: {
114-
sync: [],
115-
async: [],
116-
},
117-
},
118-
path: key,
119-
};
120-
}),
12168
})
12269
);
12370
} else {
@@ -262,7 +209,7 @@ const Manifest = (): Plugin[] => {
262209
this.emitFile({
263210
type: 'asset',
264211
fileName: mfManifestName,
265-
source: generateMFManifest(filesContainingModules),
212+
source: JSON.stringify(generateMFManifest(filesContainingModules)),
266213
});
267214
},
268215
},
@@ -312,8 +259,6 @@ const Manifest = (): Plugin[] => {
312259
// @ts-ignore
313260
const shared: ManifestItem[] = Array.from(getUsedShares())
314261
.map((shareKey) => {
315-
// assets(.css, .jpg, .svg等)其他资源, 不重要, 暂未处理
316-
if (!preloadMap[shareKey]) return;
317262
const shareItem = getNormalizeShareItem(shareKey);
318263

319264
return {
@@ -323,8 +268,8 @@ const Manifest = (): Plugin[] => {
323268
requiredVersion: shareItem.shareConfig.requiredVersion,
324269
assets: {
325270
js: {
326-
async: preloadMap[shareKey].async,
327-
sync: preloadMap[shareKey].sync,
271+
async: preloadMap?.[shareKey]?.async || [],
272+
sync: preloadMap?.[shareKey]?.sync || [],
328273
},
329274
css: {
330275
async: [],
@@ -339,14 +284,13 @@ const Manifest = (): Plugin[] => {
339284
// assets(.css, .jpg, .svg等)其他资源, 不重要, 暂未处理
340285
const formatKey = key.replace('./', '');
341286
const sourceFile = options.exposes[key].import;
342-
if (!preloadMap[sourceFile]) return;
343287
return {
344288
id: name + ':' + formatKey,
345289
name: formatKey,
346290
assets: {
347291
js: {
348-
async: preloadMap[sourceFile].async,
349-
sync: preloadMap[sourceFile].sync,
292+
async: preloadMap?.[sourceFile]?.async || [],
293+
sync: preloadMap?.[sourceFile]?.sync || [],
350294
},
351295
css: {
352296
sync: [],
@@ -384,7 +328,7 @@ const Manifest = (): Plugin[] => {
384328
remotes,
385329
exposes,
386330
};
387-
return JSON.stringify(result);
331+
return result;
388332
}
389333
};
390334

0 commit comments

Comments
 (0)