Skip to content

Commit

Permalink
revert afterStartup and trigger prefetch before startup
Browse files Browse the repository at this point in the history
This makes more sense as startup could take a while
and we can use the time to fetch some resources
  • Loading branch information
sokra committed Jun 4, 2018
1 parent dc0e1ec commit c77ec39
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 81 deletions.
6 changes: 1 addition & 5 deletions lib/MainTemplate.js
Expand Up @@ -94,7 +94,6 @@ module.exports = class MainTemplate extends Tapable {
requireExtensions: new SyncWaterfallHook(["source", "chunk", "hash"]),
beforeStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
startup: new SyncWaterfallHook(["source", "chunk", "hash"]),
afterStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
render: new SyncWaterfallHook([
"source",
"chunk",
Expand Down Expand Up @@ -133,7 +132,7 @@ module.exports = class MainTemplate extends Tapable {
if (chunk.entryModule) {
buf.push("// Load entry module and return exports");
buf.push(
`bootstrapReturn = ${this.renderRequireFunctionForModule(
`return ${this.renderRequireFunctionForModule(
hash,
chunk,
JSON.stringify(chunk.entryModule.id)
Expand Down Expand Up @@ -387,11 +386,8 @@ module.exports = class MainTemplate extends Tapable {
Template.asString(this.hooks.requireExtensions.call("", chunk, hash))
);
buf.push("");
buf.push("var bootstrapReturn;");
buf.push(Template.asString(this.hooks.beforeStartup.call("", chunk, hash)));
buf.push(Template.asString(this.hooks.startup.call("", chunk, hash)));
buf.push(Template.asString(this.hooks.afterStartup.call("", chunk, hash)));
buf.push("return bootstrapReturn;");
let source = this.hooks.render.call(
new OriginalSource(
Template.prefix(buf, " \t") + "\n",
Expand Down
31 changes: 15 additions & 16 deletions lib/web/JsonpMainTemplatePlugin.js
Expand Up @@ -384,19 +384,6 @@ class JsonpMainTemplatePlugin {
]),
"}",
"if(parentJsonpFunction) parentJsonpFunction(data);",
"while(resolves.length) {",
Template.indent("resolves.shift()();"),
"}",
withDefer
? Template.asString([
"",
"// add entry modules from loaded chunk to deferred list",
"deferredModules.push.apply(deferredModules, executeModules || []);",
"",
"// run deferred modules when all chunks ready",
"var deferResult = checkDeferredModules();"
])
: "",
withPrefetch
? Template.asString([
"// chunk prefetching for javascript",
Expand All @@ -414,7 +401,19 @@ class JsonpMainTemplatePlugin {
"});"
])
: "",
withDefer ? "return deferResult;" : ""
"while(resolves.length) {",
Template.indent("resolves.shift()();"),
"}",
withDefer
? Template.asString([
"",
"// add entry modules from loaded chunk to deferred list",
"deferredModules.push.apply(deferredModules, executeModules || []);",
"",
"// run deferred modules when all chunks ready",
"return checkDeferredModules();"
])
: ""
]),
"};",
withDefer
Expand Down Expand Up @@ -476,7 +475,7 @@ class JsonpMainTemplatePlugin {
return source;
}
);
mainTemplate.hooks.afterStartup.tap(
mainTemplate.hooks.beforeStartup.tap(
"JsonpMainTemplatePlugin",
(source, chunk, hash) => {
const prefetchChunks = chunk.getChildIdsByOrders().prefetch;
Expand Down Expand Up @@ -513,7 +512,7 @@ class JsonpMainTemplatePlugin {
.map(e => JSON.stringify(e))
.join(", ")});`,
"// run deferred modules when ready",
"bootstrapReturn = checkDeferredModules();"
"return checkDeferredModules();"
]);
} else {
return Template.asString([
Expand Down

0 comments on commit c77ec39

Please sign in to comment.