
lit-html-server
Render lit-html templates on the server as Node.js streams. Supports all lit-html types and special attribute bindings.
Usage
Install with npm/yarn
:
$ npm install --save @popeindustries/lit-html-server
...write your lit-html template:
const { html } = require('@popeindustries/lit-html-server');
function layout(data) {
return html`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>${data.title}</title>
</head>
<body>
${body(data.api)}
</body>
</html>`;
}
async function body(apiPath) {
const data = await fetchRemoteData(apiPath);
return html`<h1>${data.title}</h1>
<x-widget ?enabled=${data.hasWidget}></x-widget>
<p class=${data.invertedText ? 'negative' : ''}>${data.text}</p>`;
}
...and render:
const { render } = require('lit-html-server');
render(layout({ title: 'Home', api: '/api/home' }));
Thanks
Thanks to Thomas Parslow for the stream-template library that was the basis for this streaming implementation, and thanks to Justin Fagnani the team behind the lit-html project!