Work still in progress
This is a view engine inspired by express-react-views to compile React JSX files at request time with Express based servers.
Unlike express-react-views however, it compiles templates with 6to5.
Why? Simply because it has better support for ES6 features, and is a transpiler you're more than likely to use. As a bonus, 6to5 already can transpile JSX without any additional dependencies.
var jsxViews = require('express-6to5-jsx-views');
var app = express();
app.set('view engine', 'jsx');
app.engine('jsx', jsxViews.createEngine());And if you have a file views/DefaultPage.jsx:
import React from 'react';
var DefaultPage = React.createClass({
render: () => {
return(
<html>
<head>
<title>Hello world!</title>
</head>
<body>
<h1>Hello world, from JSX!</h1>
</body>
</html>
);
}
});
export default DefaultPage;And now you can just call the render function:
app.get('/', function(req, res) {
res.render('DefaultPage', {});
});createEngine also takes the following options:
enginedoctype(default:<!DOCTYPE html>) - the DOCTYPE string to prepend to the output automaticallystaticOutput(default:false) - if set totrue, the output will not contain any React-related markup
to5- Any 6to5 configuration can go here. By default, only
extensions: ['.jsx']is set.
- Any 6to5 configuration can go here. By default, only
Work still in progress