Skip to content

Commit 50b681f

Browse files
committed
fix: ignore hot-uptdaet asset in dev
1 parent 95c15a5 commit 50b681f

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

packages/manifest/src/ManifestManager.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import chalk from 'chalk';
22
import {
33
Stats,
44
Manifest,
5-
ManifestFileName,
65
ManifestExpose,
76
StatsExpose,
87
StatsShared,
98
ManifestShared,
109
ManifestRemote,
11-
simpleJoinRemoteEntry,
1210
StatsRemote,
1311
moduleFederationPlugin,
1412
} from '@module-federation/sdk';

packages/manifest/src/utils.ts

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ import {
1616
} from '@module-federation/dts-plugin/core';
1717
import { HOT_UPDATE_SUFFIX, PLUGIN_IDENTIFIER } from './constants';
1818

19+
function isHotFile(file: string) {
20+
return file.includes(HOT_UPDATE_SUFFIX);
21+
}
22+
23+
const collectAssets = (
24+
assets: string[],
25+
jsTargetSet: Set<string>,
26+
cssTargetSet: Set<string>,
27+
) => {
28+
assets.forEach((file) => {
29+
if (file.endsWith('.css')) {
30+
cssTargetSet.add(file);
31+
} else {
32+
if (isDev()) {
33+
if (!isHotFile(file)) {
34+
jsTargetSet.add(file);
35+
}
36+
} else {
37+
jsTargetSet.add(file);
38+
}
39+
}
40+
});
41+
};
42+
1943
function getSharedModuleName(name: string): string {
2044
const [_type, _shared, _module, _shareScope, sharedInfo] = name.split(' ');
2145
return sharedInfo.split('@').slice(0, -1).join('@');
@@ -39,19 +63,7 @@ export function getAssetsByChunkIDs(
3963
chunkIDs.forEach((chunkID) => {
4064
const chunk = arrayChunks.find((item) => item.id === chunkID);
4165
if (chunk) {
42-
[...chunk.files].forEach((asset) => {
43-
if (asset.endsWith('.css')) {
44-
assetMap[key].css.add(asset);
45-
} else {
46-
if (process.env['NODE_ENV'] === 'development') {
47-
if (!asset.includes(HOT_UPDATE_SUFFIX)) {
48-
assetMap[key].js.add(asset);
49-
}
50-
} else {
51-
assetMap[key].js.add(asset);
52-
}
53-
}
54-
});
66+
collectAssets([...chunk.files], assetMap[key].js, assetMap[key].css);
5567
}
5668
});
5769
});
@@ -152,25 +164,21 @@ export function getAssetsByChunk(chunk: Chunk): StatsAssets {
152164
type: 'sync' | 'async',
153165
): void => {
154166
[...targetChunk.groupsIterable].forEach((chunkGroup) => {
155-
chunkGroup.getFiles().forEach((file) => {
156-
if (file.endsWith('.css')) {
157-
assesSet.css[type].add(file);
158-
} else {
159-
assesSet.js[type].add(file);
160-
}
161-
});
167+
collectAssets(
168+
chunkGroup.getFiles(),
169+
assesSet.js[type],
170+
assesSet.css[type],
171+
);
162172
});
163173
};
164174
collectChunkFiles(chunk, 'sync');
165175

166176
[...chunk.getAllAsyncChunks()].forEach((asyncChunk) => {
167-
asyncChunk.files.forEach((file) => {
168-
if (file.endsWith('.css')) {
169-
assesSet.css.async.add(file);
170-
} else {
171-
assesSet.js.async.add(file);
172-
}
173-
});
177+
collectAssets(
178+
[...asyncChunk.files],
179+
assesSet.js['async'],
180+
assesSet.css['async'],
181+
);
174182
collectChunkFiles(asyncChunk, 'async');
175183
});
176184

0 commit comments

Comments
 (0)