@ -408,10 +408,11 @@ export function findExportedComponentLazy<T extends object = any>(...props: stri
/ * *
* Extract and load chunks using their entry point
* @param code An array of all the code the module factory containing the entry point ( as of using it to load chunks ) must include
* @param matcher A RegExp that returns the entry point id as the first capture group . Defaults to a matcher that captures the first entry point found in the module factory
* @param code An array of all the code the module factory containing the lazy chunk loading must include
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second . Defaults to a matcher that captures the lazy chunk loading found in the module factory
* @returns A promise that resolves when the chunks were loaded
* /
export async function extractAndLoadChunks ( code : string [ ] , matcher : RegExp = / \.el\("(.+?)"\)(?<=(\i)\.el.+?)\.then\(\2\.bind\(\2,"\1 "\)\)/) {
export async function extractAndLoadChunks ( code : string [ ] , matcher : RegExp = / Promise\.all\((\[\i\.\i\(".+?"\).+?\])\).then\(\i\.bind\(\i,"(.+?) "\)\)/) {
const module = findModuleFactory ( . . . code ) ;
if ( ! module ) {
const err = new Error ( "extractAndLoadChunks: Couldn't find module factory" ) ;
@ -432,9 +433,9 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = /\.
return ;
}
const [ , id] = match ;
if ( ! id || ! Number ( i d) ) {
const err = new Error ( "extractAndLoadChunks: Matcher didn't return a capturing group with the entry point, or the entry point returned wasn't a number") ;
const [ , rawChunkIds, entryPo intI d] = match ;
if ( ! rawChunkIds || Number . isNaN ( entryPointI d) ) {
const err = new Error ( "extractAndLoadChunks: Matcher didn't return a capturing group with the chunk ids array, or the entry point id returned as the second group wasn't a number") ;
logger . warn ( err , "Code:" , code , "Matcher:" , matcher ) ;
// Strict behaviour in DevBuilds to fail early and make sure the issue is found
@ -444,19 +445,21 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = /\.
return ;
}
await ( wreq as any ) . el ( id ) ;
return wreq ( id as any ) ;
const chunkIds = Array . from ( rawChunkIds . matchAll ( /\("(.+?)"\)/g ) ) . map ( ( m : any ) = > m [ 1 ] ) ;
await Promise . all ( chunkIds . map ( id = > wreq . e ( id ) ) ) ;
wreq ( entryPointId ) ;
}
/ * *
* This is just a wrapper around { @link extractAndLoadChunks } to make our reporter test for your webpack finds .
*
* Extract and load chunks using their entry point
* @param code An array of all the code the module factory containing the entry point ( as of using it to load chunks ) must include
* @param matcher A RegExp that returns the entry point id as the first capture group . Defaults to a matcher that captures the first entry point found in the module factory
* @returns A function that loads the chunks on first call
* @param code An array of all the code the module factory containing the lazy chunk loading must include
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second . Defaults to a matcher that captures the lazy chunk loading found in the module factory
* @returns A function that returns a promise that resolves when the chunks were loaded , on first call
* /
export function extractAndLoadChunksLazy ( code : string [ ] , matcher : RegExp = / \.el\("(.+?)"\)(?<=(\i)\.el.+?)\.then\(\2\.bind\(\2,"\1 "\)\)/) {
export function extractAndLoadChunksLazy ( code : string [ ] , matcher : RegExp = / Promise\.all\((\[\i\.\i\(".+?"\).+?\])\).then\(\i\.bind\(\i,"(.+?) "\)\)/) {
if ( IS_DEV ) lazyWebpackSearchHistory . push ( [ "extractAndLoadChunks" , [ code , matcher ] ] ) ;
return ( ) = > extractAndLoadChunks ( code , matcher ) ;