Skip to content

Commit c77ec39

Browse files
committed
revert afterStartup and trigger prefetch before startup
This makes more sense as startup could take a while and we can use the time to fetch some resources
1 parent dc0e1ec commit c77ec39

File tree

3 files changed

+76
-81
lines changed

3 files changed

+76
-81
lines changed

lib/MainTemplate.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ module.exports = class MainTemplate extends Tapable {
9494
requireExtensions: new SyncWaterfallHook(["source", "chunk", "hash"]),
9595
beforeStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
9696
startup: new SyncWaterfallHook(["source", "chunk", "hash"]),
97-
afterStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
9897
render: new SyncWaterfallHook([
9998
"source",
10099
"chunk",
@@ -133,7 +132,7 @@ module.exports = class MainTemplate extends Tapable {
133132
if (chunk.entryModule) {
134133
buf.push("// Load entry module and return exports");
135134
buf.push(
136-
`bootstrapReturn = ${this.renderRequireFunctionForModule(
135+
`return ${this.renderRequireFunctionForModule(
137136
hash,
138137
chunk,
139138
JSON.stringify(chunk.entryModule.id)
@@ -387,11 +386,8 @@ module.exports = class MainTemplate extends Tapable {
387386
Template.asString(this.hooks.requireExtensions.call("", chunk, hash))
388387
);
389388
buf.push("");
390-
buf.push("var bootstrapReturn;");
391389
buf.push(Template.asString(this.hooks.beforeStartup.call("", chunk, hash)));
392390
buf.push(Template.asString(this.hooks.startup.call("", chunk, hash)));
393-
buf.push(Template.asString(this.hooks.afterStartup.call("", chunk, hash)));
394-
buf.push("return bootstrapReturn;");
395391
let source = this.hooks.render.call(
396392
new OriginalSource(
397393
Template.prefix(buf, " \t") + "\n",

lib/web/JsonpMainTemplatePlugin.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,6 @@ class JsonpMainTemplatePlugin {
384384
]),
385385
"}",
386386
"if(parentJsonpFunction) parentJsonpFunction(data);",
387-
"while(resolves.length) {",
388-
Template.indent("resolves.shift()();"),
389-
"}",
390-
withDefer
391-
? Template.asString([
392-
"",
393-
"// add entry modules from loaded chunk to deferred list",
394-
"deferredModules.push.apply(deferredModules, executeModules || []);",
395-
"",
396-
"// run deferred modules when all chunks ready",
397-
"var deferResult = checkDeferredModules();"
398-
])
399-
: "",
400387
withPrefetch
401388
? Template.asString([
402389
"// chunk prefetching for javascript",
@@ -414,7 +401,19 @@ class JsonpMainTemplatePlugin {
414401
"});"
415402
])
416403
: "",
417-
withDefer ? "return deferResult;" : ""
404+
"while(resolves.length) {",
405+
Template.indent("resolves.shift()();"),
406+
"}",
407+
withDefer
408+
? Template.asString([
409+
"",
410+
"// add entry modules from loaded chunk to deferred list",
411+
"deferredModules.push.apply(deferredModules, executeModules || []);",
412+
"",
413+
"// run deferred modules when all chunks ready",
414+
"return checkDeferredModules();"
415+
])
416+
: ""
418417
]),
419418
"};",
420419
withDefer
@@ -476,7 +475,7 @@ class JsonpMainTemplatePlugin {
476475
return source;
477476
}
478477
);
479-
mainTemplate.hooks.afterStartup.tap(
478+
mainTemplate.hooks.beforeStartup.tap(
480479
"JsonpMainTemplatePlugin",
481480
(source, chunk, hash) => {
482481
const prefetchChunks = chunk.getChildIdsByOrders().prefetch;
@@ -513,7 +512,7 @@ class JsonpMainTemplatePlugin {
513512
.map(e => JSON.stringify(e))
514513
.join(", ")});`,
515514
"// run deferred modules when ready",
516-
"bootstrapReturn = checkDeferredModules();"
515+
"return checkDeferredModules();"
517516
]);
518517
} else {
519518
return Template.asString([

0 commit comments

Comments
 (0)