hugohua / react-view

An Koa view engine which renders React components on server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

koa-react-view

NPM version build status Test coverage David deps node version

An Koa view engine which renders React components on server.

Installation

$ npm install koa-react-view

Usage

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'});
});

Options

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'

ctx.state

koa-react-view support ctx.state in koa.

License

MIT

About

An Koa view engine which renders React components on server


Languages

Language:JavaScript 99.8%Language:Makefile 0.1%Language:CSS 0.0%