Skip to content

Commit 1fe6022

Browse files
committed
only decorate the jsonp function
this allows mutliple instances of bundles of the same build fixes karma-webpack#2
1 parent a134fae commit 1fe6022

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎lib/JsonpMainTemplate.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,15 @@ JsonpMainTemplate.prototype.renderInit = function(hash, chunk) {
8080
buf.push(
8181
"",
8282
"// install a JSONP callback for chunk loading",
83+
"var parentJsonpFunction = window[" + JSON.stringify(jsonpFunction) + "];",
8384
"window[" + JSON.stringify(jsonpFunction) + "] = function webpackJsonpCallback(chunkIds, moreModules) {",
8485
this.indent([
8586
'// add "moreModules" to the modules object,',
8687
'// then flag all "chunkIds" as loaded and fire callback',
87-
"var moduleId, chunkId, callbacks = [];",
88-
"while(chunkIds.length) {",
88+
"var moduleId, chunkId, i = 0, callbacks = [];",
89+
"for(;i < chunkIds.length; i++) {",
8990
this.indent([
90-
"chunkId = chunkIds.shift();",
91+
"chunkId = chunkIds[i];",
9192
"if(installedChunks[chunkId])",
9293
this.indent("callbacks.push.apply(callbacks, installedChunks[chunkId]);"),
9394
"installedChunks[chunkId] = 0;"
@@ -96,6 +97,7 @@ JsonpMainTemplate.prototype.renderInit = function(hash, chunk) {
9697
"for(moduleId in moreModules) {",
9798
this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")),
9899
"}",
100+
"if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules);",
99101
"while(callbacks.length)",
100102
this.indent("callbacks.shift().call(null, " + this.requireFn + ");"),
101103
(this.entryPointInChildren(chunk) ? [

0 commit comments

Comments
 (0)