So the problem with this was that I misunderstood the way template precompilation works with hogan
: It does not output a vanilla JS "function version" of your template but a pre-rendered string that you still need to pass to Hogan.template(str)
.
Since the stripped down template only version of hogan is only 2.5kb I just included this into my AMD module and got everything working just fine like:
var fs = require('fs');
var Hogan = require('hogan.js');
var output = 'define(function(){\n';
output += 'var Templates = {};\n';
output += fs.readFileSync('template.min.js', 'utf-8') + '\n';
fs.readdir(process.cwd(), function(err, data){
if (err) console.log(err);
data.forEach(function(el){
var s = el.split('.');
if (s[s.length - 1] === 'html'){
var precompiled = Hogan.compile(fs.readFileSync(process.cwd() + + el, 'utf-8'), {asString: true});
output += 'Templates[\'' + el.split('.')[0] + '\'] = new Hogan.Template(' + precompiled + ');\n';
console.log('Compiled template:', el);
}
});
output += 'return Templates;});';
fs.writeFile(process.cwd() + '/templates.js', output, function(){
console.log('Template build succeeded!');
});
});