@@ -70,15 +70,14 @@ class AsyncEntryStartupPlugin {
70
70
getChunkByName (
71
71
compilation : Compilation ,
72
72
dependOn : string [ ] ,
73
- ) : ( string | number | undefined ) [ ] {
74
- const byname = [ ] ;
73
+ byname : Set < Chunk > ,
74
+ ) {
75
75
for ( const name of dependOn ) {
76
76
const chunk = compilation . namedChunks . get ( name ) ;
77
77
if ( chunk ) {
78
- byname . push ( chunk . id || chunk . name ) ;
78
+ byname . add ( chunk ) ;
79
79
}
80
80
}
81
- return byname ;
82
81
}
83
82
84
83
private _handleRenderStartup ( compiler : Compiler , compilation : Compilation ) {
@@ -118,36 +117,59 @@ class AsyncEntryStartupPlugin {
118
117
119
118
const requirements =
120
119
compilation . chunkGraph . getTreeRuntimeRequirements ( runtimeItem ) ;
121
- const hasRemoteModules =
122
- compilation . chunkGraph . getChunkModulesIterableBySourceType (
123
- upperContext . chunk ,
124
- 'remote' ,
125
- ) ;
126
- const consumeShares =
127
- compilation . chunkGraph . getChunkModulesIterableBySourceType (
128
- upperContext . chunk ,
129
- 'consume-shared' ,
130
- ) ;
120
+
131
121
const entryOptions = upperContext . chunk . getEntryOptions ( ) ;
132
- const initialChunks = Array . from (
133
- upperContext . chunk . getAllInitialChunks ( ) ,
134
- ) . map ( ( chunk : Chunk ) => chunk . id ) ;
122
+ const chunkInitialsSet = new Set (
123
+ compilation . chunkGraph . getChunkEntryDependentChunksIterable (
124
+ upperContext . chunk ,
125
+ ) ,
126
+ ) ;
127
+
128
+ chunkInitialsSet . add ( upperContext . chunk ) ;
135
129
const dependOn = entryOptions ?. dependOn || [ ] ;
136
- const dependOnIDs = this . getChunkByName ( compilation , dependOn ) ;
137
- const chunksToRef = [ ...dependOnIDs , ...initialChunks ] ;
130
+ this . getChunkByName ( compilation , dependOn , chunkInitialsSet ) ;
131
+
132
+ const initialChunks = [ ] ;
133
+
134
+ let hasRemoteModules = false ;
135
+ let consumeShares = false ;
136
+
137
+ for ( const chunk of chunkInitialsSet ) {
138
+ initialChunks . push ( chunk . id ) ;
139
+ if ( ! hasRemoteModules ) {
140
+ hasRemoteModules = Boolean (
141
+ compilation . chunkGraph . getChunkModulesIterableBySourceType (
142
+ chunk ,
143
+ 'remote' ,
144
+ ) ,
145
+ ) ;
146
+ }
147
+ if ( ! consumeShares ) {
148
+ consumeShares = Boolean (
149
+ compilation . chunkGraph . getChunkModulesIterableBySourceType (
150
+ chunk ,
151
+ 'consume-shared' ,
152
+ ) ,
153
+ ) ;
154
+ }
155
+ if ( hasRemoteModules && consumeShares ) {
156
+ break ;
157
+ }
158
+ }
138
159
139
160
remotes = this . _getRemotes (
140
161
compiler . webpack . RuntimeGlobals ,
141
162
requirements ,
142
- Boolean ( hasRemoteModules ) ,
143
- chunksToRef ,
163
+ hasRemoteModules ,
164
+ initialChunks ,
144
165
remotes ,
145
166
) ;
167
+
146
168
shared = this . _getShared (
147
169
compiler . webpack . RuntimeGlobals ,
148
170
requirements ,
149
- Boolean ( consumeShares ) ,
150
- chunksToRef ,
171
+ consumeShares ,
172
+ initialChunks ,
151
173
shared ,
152
174
) ;
153
175
}
0 commit comments