An Koa view engine which renders React components on server.
$ npm install koa-react-view
var react = require('koa-react-view');
var path = require('path');
var koa = require('koa');
var app = koa();
var viewpath = path.join(__dirname, 'views');
var assetspath = path.join(__dirname, 'public');
react(app, {
views: viewpath,
babel: {
only: [
viewpath,
assetspath
]
}
});
app.use(function* () {
this.render(home, {foo: 'bar'});
});
option | values | default |
---|---|---|
doctype |
any string that can be used as a doctype, this will be prepended to your document | "<!DOCTYPE html>" |
beautify |
true : beautify markup before outputting (note, this can affect rendering due to additional whitespace) |
false |
views |
the root directory of view files | path.join(__dirname, 'views') |
extname |
the default view file's extname | jsx |
writeResp |
true : writes the body response automatically |
true |
babel |
the options for babel/register | {only: options.views} |
cache |
true : cache all the view files |
process.env.NODE_ENV === 'production' |
koa-react-view
support ctx.state in koa.
MIT