Cross-tp is a convenient template builder. After configuring and running the script, go out, get the js file you can connect to your project.
Using
import { CrossTpl } from 'cross-tpl'
const crossTpl = new CrossTpl({
dirname: __dirname,
src: 'view',
upload: false
});
crossTpl.create();
crossTpl.upload();
crossTpl.build();
crossTpl.watch();
Result | source
CrossTplCore.templates.set('8cd728920dc49356699b7ef285a1323b', "PGRpdiBpZD0iY3Jvc3MtdHBsIj5IaSEgTXkgbmFtZSBpcyBDcm9zc0pzIDopIDwvZGl2Pg==" );
CrossTemplates.render = function (name, handler) {
if (handler === void 0) { handler = false; }
if (CrossTplCore.options.dirHash) {
name = Md5.init(name);
}
var content = CrossTplCore.templates.get(name) || '';
if (CrossTplCore.options.contentBase64 && content) {
content = decodeURIComponent(atob(content).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
return content || '';
};
Result | use of source
import { CrossTemplates } from 'cross-tpl/src/dist/CrossTemplates';
const template = CrossTemplates.render('hi.html');
console.log(template);