@@ -164,24 +164,33 @@ class ModuleChunkFormatPlugin {
164164 return source ;
165165 }
166166 } ;
167- hooks . renderMain . tap ( PLUGIN_NAME , ( modules , renderContext ) => {
168- const { chunk, chunkGraph } = renderContext ;
169- const entryDependentChunks =
170- chunkGraph . getChunkEntryDependentChunksIterable ( chunk ) ;
171- const sourceWithDependentChunks = withDependentChunks (
172- /** @type {Set<Chunk> } */ ( entryDependentChunks ) ,
173- chunkGraph ,
174- chunk
175- ) ;
176- if ( ! sourceWithDependentChunks ) {
177- return modules ;
167+ hooks . renderStartup . tap (
168+ PLUGIN_NAME ,
169+ ( modules , _lastModule , renderContext ) => {
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 ;
186+ }
187+ const source = new ConcatSource ( ) ;
188+ source . add ( sourceWithDependentChunks ) ;
189+ source . add ( "\n" ) ;
190+ source . add ( modules ) ;
191+ return source ;
178192 }
179- const source = new ConcatSource ( ) ;
180- source . add ( modules ) ;
181- source . add ( "\n" ) ;
182- source . add ( sourceWithDependentChunks ) ;
183- return source ;
184- } ) ;
193+ ) ;
185194 hooks . renderChunk . tap ( PLUGIN_NAME , ( modules , renderContext ) => {
186195 const { chunk, chunkGraph, runtimeTemplate } = renderContext ;
187196 const hotUpdateChunk = chunk instanceof HotUpdateChunk ? chunk : null ;
0 commit comments