@@ -16,6 +16,30 @@ import {
16
16
} from '@module-federation/dts-plugin/core' ;
17
17
import { HOT_UPDATE_SUFFIX , PLUGIN_IDENTIFIER } from './constants' ;
18
18
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
+
19
43
function getSharedModuleName ( name : string ) : string {
20
44
const [ _type , _shared , _module , _shareScope , sharedInfo ] = name . split ( ' ' ) ;
21
45
return sharedInfo . split ( '@' ) . slice ( 0 , - 1 ) . join ( '@' ) ;
@@ -39,19 +63,7 @@ export function getAssetsByChunkIDs(
39
63
chunkIDs . forEach ( ( chunkID ) => {
40
64
const chunk = arrayChunks . find ( ( item ) => item . id === chunkID ) ;
41
65
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 ) ;
55
67
}
56
68
} ) ;
57
69
} ) ;
@@ -152,25 +164,21 @@ export function getAssetsByChunk(chunk: Chunk): StatsAssets {
152
164
type : 'sync' | 'async' ,
153
165
) : void => {
154
166
[ ...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
+ ) ;
162
172
} ) ;
163
173
} ;
164
174
collectChunkFiles ( chunk , 'sync' ) ;
165
175
166
176
[ ...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
+ ) ;
174
182
collectChunkFiles ( asyncChunk , 'async' ) ;
175
183
} ) ;
176
184
0 commit comments