@@ -236,9 +236,21 @@ class JsonpMainTemplatePlugin {
236236 mainTemplate . hooks . linkPrefetch . tap (
237237 "JsonpMainTemplatePlugin" ,
238238 ( _ , chunk , hash ) => {
239+ const crossOriginLoading =
240+ mainTemplate . outputOptions . crossOriginLoading ;
241+
239242 return Template . asString ( [
240243 "var link = document.createElement('link');" ,
244+ crossOriginLoading
245+ ? `link.crossOrigin = ${ JSON . stringify ( crossOriginLoading ) } ;`
246+ : "" ,
247+ `if (${ mainTemplate . requireFn } .nc) {` ,
248+ Template . indent (
249+ `link.setAttribute("nonce", ${ mainTemplate . requireFn } .nc);`
250+ ) ,
251+ "}" ,
241252 'link.rel = "prefetch";' ,
253+ 'link.as = "script";' ,
242254 "link.href = jsonpScriptSrc(chunkId);"
243255 ] ) ;
244256 }
@@ -292,7 +304,7 @@ class JsonpMainTemplatePlugin {
292304 "" ,
293305 "// chunk preloadng for javascript" ,
294306 "" ,
295- `var chunkPreloadMap = ${ JSON . stringify ( chunkMap , null , "\t" ) } ` ,
307+ `var chunkPreloadMap = ${ JSON . stringify ( chunkMap , null , "\t" ) } ; ` ,
296308 "" ,
297309 "var chunkPreloadData = chunkPreloadMap[chunkId];" ,
298310 "if(chunkPreloadData) {" ,
@@ -344,7 +356,7 @@ class JsonpMainTemplatePlugin {
344356 "var chunkIds = data[0];" ,
345357 "var moreModules = data[1];" ,
346358 withDefer ? "var executeModules = data[2];" : "" ,
347- ... ( withPrefetch ? [ "var prefetchChunks = data[3] || []" ] : [ ] ) ,
359+ withPrefetch ? "var prefetchChunks = data[3] || [];" : "" ,
348360 '// add "moreModules" to the modules object,' ,
349361 '// then flag all "chunkIds" as loaded and fire callback' ,
350362 "var moduleId, chunkId, i = 0, resolves = [];" ,
@@ -382,11 +394,11 @@ class JsonpMainTemplatePlugin {
382394 "deferredModules.push.apply(deferredModules, executeModules || []);" ,
383395 "" ,
384396 "// run deferred modules when all chunks ready" ,
385- "return checkDeferredModules();"
397+ "var deferResult = checkDeferredModules();"
386398 ] )
387399 : "" ,
388- ... ( withPrefetch
389- ? [
400+ withPrefetch
401+ ? Template . asString ( [
390402 "// chunk prefetching for javascript" ,
391403 "var head = document.getElementsByTagName('head')[0];" ,
392404 "prefetchChunks.forEach(function(chunkId) {" ,
@@ -400,8 +412,9 @@ class JsonpMainTemplatePlugin {
400412 "}"
401413 ] ) ,
402414 "});"
403- ]
404- : [ ] )
415+ ] )
416+ : "" ,
417+ withDefer ? "return deferResult;" : ""
405418 ] ) ,
406419 "};" ,
407420 withDefer
@@ -463,7 +476,7 @@ class JsonpMainTemplatePlugin {
463476 return source ;
464477 }
465478 ) ;
466- mainTemplate . hooks . beforeStartup . tap (
479+ mainTemplate . hooks . afterStartup . tap (
467480 "JsonpMainTemplatePlugin" ,
468481 ( source , chunk , hash ) => {
469482 const prefetchChunks = chunk . getChildIdsByOrders ( ) . prefetch ;
@@ -474,9 +487,9 @@ class JsonpMainTemplatePlugin {
474487 ) {
475488 return Template . asString ( [
476489 source ,
477- `webpackJsonpCallback([${ JSON . stringify (
478- chunk . ids
479- ) } , {}, null, ${ JSON . stringify ( prefetchChunks ) } ]) `
490+ `webpackJsonpCallback([[], {}, 0, ${ JSON . stringify (
491+ prefetchChunks
492+ ) } ]); `
480493 ] ) ;
481494 }
482495 return source ;
@@ -500,7 +513,7 @@ class JsonpMainTemplatePlugin {
500513 . map ( e => JSON . stringify ( e ) )
501514 . join ( ", " ) } );`,
502515 "// run deferred modules when ready" ,
503- "return checkDeferredModules();"
516+ "bootstrapReturn = checkDeferredModules();"
504517 ] ) ;
505518 } else {
506519 return Template . asString ( [
0 commit comments