预编译为纯HTML的手把

有没有办法将Handlebars模板预编译为纯HTML? 把手预编译产生一个js文件。 我可以在节点上运行JS来生成一个HTML文件吗? 这就是我想要的:

// Get a Handlebars instance var hb = require("handlebars"); // Load a template import fs = require('fs'); var template:string = fs.readFileSync('templates/template.handlebars','utf8'); // Compile said template var compiled = hb.precompile(template); // Write JS file fs.writeFileSync('compiled/template.js', compiled); var test = compiled.main(); // Write HTML file fs.writeFileSync('compiled/template.html', test); 

这会失败,因为编译.main不是一个函数。 在那里有一个主要的function,我正在试图find。

find解决scheme。 您不需要预编译,只需编译然后运行已编译的模板:

 // Get a Handlebars instance var hb = require("handlebars"); // Load a template import fs = require('fs'); var template:string = fs.readFileSync('templates/template.handlebars','utf8'); // Compile said template var compiled = hb.compile(template); var html = compiled({}); // Write HTML file fs.writeFileSync('compiled/template.html', html); 

可惜这不是在文档中。