Skip to content

Commit a26fb5d

Browse files
author
Chuck Dumont
authored
Merge pull request #303 from chuckdumont/work2
Don't require that entry bundles be loaded first
2 parents 19ee409 + c2339c1 commit a26fb5d

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/DojoAMDChunkTemplatePlugin.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,17 @@ module.exports = class DojoAMDChunkTemplatePlugin {
5656

5757
const buf = [];
5858
buf.push("(function(){");
59-
buf.push(`(this||window)[${jsonpFn}].registerAbsMids({`);
59+
buf.push(`var absMids = {`);
6060
buf.push(callSyncWaterfall(chunkTemplate, "render absMids", "", chunk));
61-
buf.push("})");
61+
buf.push("};");
62+
buf.push("var globalObj = this||window;");
63+
buf.push(`var jsonpArray = globalObj[${jsonpFn}] = globalObj[${jsonpFn}] || [];`);
64+
buf.push("if (jsonpArray.registerAbsMids) {");
65+
buf.push(" jsonpArray.registerAbsMids(absMids);");
66+
buf.push("} else {");
67+
buf.push(" var absMidsWaiting = jsonpArray.absMidsWaiting = jsonpArray.absMidsWaiting || [];");
68+
buf.push(" absMidsWaiting.push(absMids);");
69+
buf.push("}");
6270
buf.push("})(),");
6371
return new ConcatSource(this.asString(buf), source);
6472
}
@@ -94,6 +102,6 @@ module.exports = class DojoAMDChunkTemplatePlugin {
94102

95103
hash(hash) {
96104
hash.update("DojoAMDChunkTemplate");
97-
hash.update("3"); // Increment this whenever the template code above changes
105+
hash.update("4"); // Increment this whenever the template code above changes
98106
}
99107
};

lib/DojoAMDMainTemplatePlugin.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ module.exports = class DojoAMDMainTemplatePlugin {
9393
const [runtimeSource, asyncSource] = ['main', 'async'].map(type => Template.getFunctionContent(runtime[type])
9494
.replace(/__webpack_require__/g, mainTemplate.requireFn)
9595
.replace(/__async__/g, (!!this.options.async).toString()));
96+
const jsonpFn = JSON.stringify(mainTemplate.outputOptions.jsonpFunction);
9697
const buf = [];
9798
buf.push(runtimeSource);
9899
if (this.options.async) {
@@ -105,7 +106,6 @@ module.exports = class DojoAMDMainTemplatePlugin {
105106
buf.push("");
106107
buf.push((callSyncWaterfall(mainTemplate, "dojo-global-require", "globalObj.require = req;")));
107108
if(needChunkLoadingCode(chunk)) {
108-
const jsonpFn = JSON.stringify(mainTemplate.outputOptions.jsonpFunction);
109109
buf.push(this.indent(
110110
`(this||window)[${jsonpFn}].registerAbsMids = registerAbsMids;`
111111
));
@@ -170,6 +170,13 @@ but the loader specified at ${this.embeddedLoaderFilename} was built without the
170170
if (loaderConfig.has && loaderConfig.has['dojo-undef-api']) {
171171
buf.push("req.undef = " + Template.getFunctionContent(runtime.undef));
172172
}
173+
if(needChunkLoadingCode(chunk)) {
174+
buf.push(`var absMidsWaiting = globalObj[${jsonpFn}].absMidsWaiting;`);
175+
buf.push("if (absMidsWaiting) {");
176+
buf.push(" absMidsWaiting.forEach(registerAbsMids);");
177+
buf.push(` delete globalObj[${jsonpFn}].absMidsWaiting;`);
178+
buf.push("}");
179+
}
173180
const makeDeprecatedReq = Template.getFunctionContent(runtime.makeDeprecatedReq)
174181
.replace(/__webpack_require__\.dj/g, djProp);
175182
return this.asString([
@@ -230,7 +237,7 @@ but the loader specified at ${this.embeddedLoaderFilename} was built without the
230237
hash(hash) {
231238
const {options} = this;
232239
hash.update("DojoAMDMainTemplate");
233-
hash.update("11"); // Increment this whenever the template code above changes
240+
hash.update("12"); // Increment this whenever the template code above changes
234241
if (util.isString(options.loaderConfig)) {
235242
hash.update(options.loaderConfig); // loading the config as a module, so any any changes to the
236243
// content will be detected at the module level

0 commit comments

Comments
 (0)