@@ -168,27 +168,30 @@ class ModuleChunkFormatPlugin {
168
168
PLUGIN_NAME ,
169
169
( modules , _lastModule , renderContext ) => {
170
170
const { chunk, chunkGraph } = renderContext ;
171
- if ( ! chunk . hasRuntime ( ) ) {
172
- return modules ;
173
- }
174
- const entryDependentChunks =
175
- chunkGraph . getChunkEntryDependentChunksIterable ( chunk ) ;
176
- const sourceWithDependentChunks = withDependentChunks (
177
- /** @type {Set<Chunk> } */ ( entryDependentChunks ) ,
178
- chunkGraph ,
179
- chunk
180
- ) ;
181
- if ( ! sourceWithDependentChunks ) {
182
- return modules ;
183
- }
184
- if ( modules . size ( ) === 0 ) {
185
- return sourceWithDependentChunks ;
171
+ if (
172
+ chunkGraph . getNumberOfEntryModules ( chunk ) > 0 &&
173
+ chunk . hasRuntime ( )
174
+ ) {
175
+ const entryDependentChunks =
176
+ chunkGraph . getChunkEntryDependentChunksIterable ( chunk ) ;
177
+ const sourceWithDependentChunks = withDependentChunks (
178
+ /** @type {Set<Chunk> } */ ( entryDependentChunks ) ,
179
+ chunkGraph ,
180
+ chunk
181
+ ) ;
182
+ if ( ! sourceWithDependentChunks ) {
183
+ return modules ;
184
+ }
185
+ if ( modules . size ( ) === 0 ) {
186
+ return sourceWithDependentChunks ;
187
+ }
188
+ const source = new ConcatSource ( ) ;
189
+ source . add ( sourceWithDependentChunks ) ;
190
+ source . add ( "\n" ) ;
191
+ source . add ( modules ) ;
192
+ return source ;
186
193
}
187
- const source = new ConcatSource ( ) ;
188
- source . add ( sourceWithDependentChunks ) ;
189
- source . add ( "\n" ) ;
190
- source . add ( modules ) ;
191
- return source ;
194
+ return modules ;
192
195
}
193
196
) ;
194
197
hooks . renderChunk . tap ( PLUGIN_NAME , ( modules , renderContext ) => {
@@ -238,20 +241,14 @@ class ModuleChunkFormatPlugin {
238
241
}
239
242
const final = i + 1 === entries . length ;
240
243
const moduleId = chunkGraph . getModuleId ( module ) ;
241
- const entryDependentChunks = /** @type {Set<Chunk> } */ (
242
- chunkGraph . getChunkEntryDependentChunksIterable ( chunk )
243
- ) ;
244
244
const chunks = getAllChunks (
245
245
/** @type {Entrypoint } */ ( entrypoint ) ,
246
246
/** @type {Chunk } */ ( runtimeChunk ) ,
247
247
undefined
248
248
) ;
249
249
const processChunks = new Set ( ) ;
250
250
for ( const _chunk of chunks ) {
251
- if (
252
- loadedChunks . has ( _chunk ) ||
253
- entryDependentChunks . has ( _chunk )
254
- ) {
251
+ if ( loadedChunks . has ( _chunk ) ) {
255
252
continue ;
256
253
}
257
254
loadedChunks . add ( _chunk ) ;
0 commit comments