@@ -16,6 +16,30 @@ import {
1616} from '@module-federation/dts-plugin/core' ;
1717import { 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+
1943function 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