From 85d39fa0076dd2de2428d85e05a2bb4768ae96d4 Mon Sep 17 00:00:00 2001 From: lichengyin Date: Fri, 22 Jan 2016 12:52:18 +0800 Subject: [PATCH] feature: support preload packages before start server --- src/config/sys/alias.js | 2 +- src/index.js | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/config/sys/alias.js b/src/config/sys/alias.js index 568e6fef..308775b1 100644 --- a/src/config/sys/alias.js +++ b/src/config/sys/alias.js @@ -13,7 +13,7 @@ export default { app: `${rootPath}core${sep}app.js`, http: `${rootPath}core${sep}http.js`, view: `${rootPath}core${sep}view.js`, - auth: `${rootPath}util${sep}auth.js`, + // auth: `${rootPath}util${sep}auth.js`, cookie: `${rootPath}util${sep}cookie.js`, validator: `${rootPath}util${sep}validator.js`, await: `${rootPath}util${sep}await.js`, diff --git a/src/index.js b/src/index.js index 046a2054..79efef12 100644 --- a/src/index.js +++ b/src/index.js @@ -432,12 +432,26 @@ export default class { think.autoCompile = true; } + /** + * pre require + * @return {} [] + */ + preload(){ + let startTime = Date.now(); + for(let name in thinkData.alias){ + think.require(thinkData.alias[name]); + } + think.log('preload packages finished', 'PRELOAD', startTime); + } /** * run * @return {} [] */ - run(){ + run(preload){ this.start(); + if(preload){ + this.preload(); + } return think.require('app').run(); } /**