@@ -7,6 +7,8 @@ const Preload = require('./Preload');
77const { noHeadException } = require ( './Messages/Exception' ) ;
88
99/** @typedef {import('webpack').Compilation } Compilation */
10+ /** @typedef {import("webpack/lib/Entrypoint") } Entrypoint */
11+ /** @typedef {import("webpack/lib/ChunkGroup") } ChunkGroup */
1012
1113/**
1214 * @typedef {Object } CollectionData
@@ -288,11 +290,13 @@ class Collection {
288290 for ( let [ resource , { type, name, entries } ] of this . assets ) {
289291 if ( type !== Collection . type . script ) continue ;
290292
293+ /** @type {Entrypoint } entrypoint */
291294 const entrypoint = namedChunkGroups . get ( name ) ;
292295
293296 // prevent error when in watch mode after removing a script in the template
294297 if ( ! entrypoint ) continue ;
295298
299+ const childrenFiles = this . #getChildrenFiles( entrypoint ) ;
296300 const chunkFiles = new Set ( ) ;
297301
298302 for ( const { id, files, auxiliaryFiles } of entrypoint . chunks ) {
@@ -310,7 +314,7 @@ class Collection {
310314 splitChunkIds . add ( id ) ;
311315 }
312316
313- const hasSplitChunks = chunkFiles . size > 1 ;
317+ const hasChunks = chunkFiles . size > 1 ;
314318
315319 // do flat the Map<string, Set>
316320 const entryFilenames = new Set ( ) ;
@@ -322,16 +326,17 @@ class Collection {
322326 // let's show an original error
323327 if ( ! assets . hasOwnProperty ( entryFile ) ) continue ;
324328
325- const data = { type, resource, chunks : [ ] } ;
329+ const data = { type, resource, chunks : [ ] , children : [ ] } ;
326330 let injectedChunks ;
327331
328- if ( hasSplitChunks ) {
332+ if ( hasChunks ) {
329333 if ( ! chunkCache . has ( entryFile ) ) chunkCache . set ( entryFile , new Set ( ) ) ;
330334 injectedChunks = chunkCache . get ( entryFile ) ;
331335 }
332336
337+ // split chunks
333338 for ( let chunkFile of chunkFiles ) {
334- if ( hasSplitChunks ) {
339+ if ( hasChunks ) {
335340 if ( injectedChunks . has ( chunkFile ) ) continue ;
336341 injectedChunks . add ( chunkFile ) ;
337342 }
@@ -343,6 +348,20 @@ class Collection {
343348 data . chunks . push ( { inline, chunkFile, assetFile } ) ;
344349 }
345350
351+ // dynamic imported chunks
352+ for ( let chunkFile of childrenFiles ) {
353+ if ( hasChunks ) {
354+ if ( injectedChunks . has ( chunkFile ) ) continue ;
355+ injectedChunks . add ( chunkFile ) ;
356+ }
357+
358+ const assetFile = this . pluginOption . getAssetOutputFile ( chunkFile , entryFile ) ;
359+ const inline = this . pluginOption . isInlineJs ( resource , chunkFile ) ;
360+
361+ splitChunkFiles . add ( chunkFile ) ;
362+ data . children . push ( { inline, chunkFile, assetFile } ) ;
363+ }
364+
346365 const entryData = this . data . get ( entryFile ) ;
347366
348367 if ( entryData ) {
@@ -369,6 +388,24 @@ class Collection {
369388 }
370389 }
371390
391+ /**
392+ * @param {Entrypoint } entrypoint
393+ * @return {Array<string> }
394+ */
395+ #getChildrenFiles( entrypoint ) {
396+ let files = [ ] ;
397+ const children = entrypoint . getChildren ( ) ;
398+
399+ for ( const chunkGroup of children ) {
400+ let chunkFiles = chunkGroup . getFiles ( ) ;
401+ if ( chunkFiles ) {
402+ files . push ( ...chunkFiles ) ;
403+ }
404+ }
405+
406+ return files ;
407+ }
408+
372409 /**
373410 * Whether the output filename is a template entrypoint.
374411 *
0 commit comments