@@ -31,6 +31,7 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
3131 var chunkFilename = this . outputOptions . chunkFilename || "[id]." + filename ;
3232 var chunkMaps = chunk . getChunkMaps ( ) ;
3333 var crossOriginLoading = this . outputOptions . crossOriginLoading ;
34+ var chunkLoadTimeout = this . outputOptions . chunkLoadTimeout || 120000 ;
3435 return this . asString ( [
3536 "if(installedChunks[chunkId] === 0)" ,
3637 this . indent ( [
@@ -49,6 +50,7 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
4950 "script.type = 'text/javascript';" ,
5051 "script.charset = 'utf-8';" ,
5152 "script.async = true;" ,
53+ "script.timeout = " + chunkLoadTimeout + ";" ,
5254 crossOriginLoading ? "script.crossOrigin = '" + crossOriginLoading + "';" : "" ,
5355 "script.src = " + this . requireFn + ".p + " +
5456 this . applyPluginsWaterfall ( "asset-path" , JSON . stringify ( chunkFilename ) , {
@@ -70,6 +72,22 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
7072 name : "\" + (" + JSON . stringify ( chunkMaps . name ) + "[chunkId]||chunkId) + \""
7173 }
7274 } ) + ";" ,
75+ "var timeout = setTimeout(onScriptComplete, " + chunkLoadTimeout + ");" ,
76+ "script.onerror = script.onload = onScriptComplete;" ,
77+ "function onScriptComplete() {" ,
78+ this . indent ( [
79+ "// avoid mem leaks in IE." ,
80+ "script.onerror = script.onload = null;" ,
81+ "clearTimeout(timeout);" ,
82+ "var chunk = installedChunks[chunkId];" ,
83+ "if(chunk !== 0) {" ,
84+ this . indent ( [
85+ "if(chunk) chunk[1](new Error('Loading chunk ' + chunkId + ' failed.'));" ,
86+ "installedChunks[chunkId] = undefined;"
87+ ] ) ,
88+ "}"
89+ ] ) ,
90+ "};" ,
7391 "head.appendChild(script);" ,
7492 "" ,
7593 "var promise = new Promise(function(resolve, reject) {" ,
0 commit comments