builder-isv
Version:
ISV 模块本地预览与云构建器
60 lines (55 loc) • 1.54 kB
JavaScript
/**
* @author 龙喜<xiaolong.lxl@alibaba-inc.com>
* @description 渲染器(包括页面渲染与资源构建)
*/
;
module.exports = {
/**
* 将渲染与构建逻辑匹配到当前分支(云构建也用到)
* @param {JSONStore} abcInfo
* @param {JSONStore} packageInfo
* @returns {*|boolean}
*/
match: function(abcInfo, packageInfo) {
return abcInfo && abcInfo.info && abcInfo.info.extraLib === 'reactjs';
},
/**
* 页面渲染器
* @param params
* @param queries
* @param headers
* @param {JSONStore} abcInfo
* @param {JSONStore} packageInfo
*/
render: function*(params, queries, headers, abcInfo, packageInfo) {
const renderPage = require('../../lib/getRenderedPage');
const rendererFactory = new (require('../../models/rendererFactory'));
const renderer = yield rendererFactory.getRenderer(params.type, params.name);
// 等待 deps 生成
yield renderer.waitUntilBundleFinished();
return yield renderPage(params, queries, headers, abcInfo, packageInfo);
},
/**
* 返回构建器 Class
* @returns {*}
*/
getBuilder: function() {
return require('./builderRax');
},
/**
* 自定义路由
* {String} route: {Function} renderer
*/
routes: {
/**
* 渲染方法
* @param req
* @param resp
* @param {JSONStore} abcInfo
* @param {JSONStore} packageInfo
*/
'/:type/:name/test.html': function*(req, resp, abcInfo, packageInfo) {
resp.send('test ok.');
}
}
};