hapi-riot
Helps you Render Riot Components Server-side in your Hapi.js Web Application.
Why?
We really like the simplicity of Riot.js.
If you want to know why we think Riot.js is (much) "better"
than other "View Libraries" or "Frameworks",
please see:
What?
Server-side rendering of Riot Components using the Vision Plugin.
How?
Install
npm install hapi vision hapi-riot --save
Use it
server.register(Vision, (err) => {
if (err) {
console.log('Failed to load vision.');
}
server.views({
engines: {
tag: require('hapi-riot')
},
relativeTo: __dirname,
path: 'views'
});
server.route({
method: 'GET',
path: '/',
handler: (request, reply) => {
reply.view('index', { title: 'My Amazing Title!');
}
});
}
More/Complete examples are in the /examples
directory.
If you need more, just ask! https://github.com/dwyl/hapi-riot/issues
Optional compileOptions
(That Simplify Your Life!)
We have added a few features to simplify our own projects.
These are documented below, but are not meant to be fit for everyone.
None are enabled by default so if you "just" want to render simple
Riot Components as your Hapi Views, follow the simple example.
Doctype (default)
Riot does not like it when you include "unbalanced" tags.
So, instead of manually including the DOCTYPE
declaration at the top
of your tag it gets "injected" at the top of the rendered view
by hapi-riot
.
removeCache
While you are developing your app you typically don't want
your views to be cached, however, when you deploy your app
by setting NODE_ENV=production
views will be cached.
If for any reason you want to cache your views during development,
or if you need to debug production on your localhost,
set the compileOptions.removeCache: false
like this:
server.views({
engines: {
tag: require('hapi-riot')
},
relativeTo: __dirname,
path: 'views',
compileOptions: {
removeCache: false
}
});