Taggable template literals
npm install --save-dev rollup-plugin-template-literal
import templateLiteral from 'rollup-plugin-template-literal';
export default {
input: 'index.js',
plugins: [
templateLiteral({
include: '**/*.js.html', // required
exclude: '**/*.js', // optional
tags: 'optional' // one of 'off', 'optional', 'required'; default: 'required'
propsKey: 'props' // optional; default: 'props'
}),
],
};
<p>${props.message}</p>
import template from './template.js.html';
const props = {
message: 'oh hi',
};
const div = document.createElement('div');
div.innerHTML = template(
props // will be accessible in template string as propsKey
);
// result: div.innerHTML = '<p>oh hi</p>'
import { html } from 'common-tags';
import template from './template.js.html';
const props = {
message: 'oh hi',
};
const div = document.createElement('div');
div.innerHTML = template(
props, // will be accessible in template string via propsKey
html // template string will be run through the passed tag function
);
// result: div.innerHTML = '<p>oh hi</p>'