Skip to content

Instantly share code, notes, and snippets.

@richard-flosi
Created April 9, 2014 17:59
Show Gist options
  • Save richard-flosi/10297549 to your computer and use it in GitHub Desktop.
Save richard-flosi/10297549 to your computer and use it in GitHub Desktop.
Hem precompiler for nunjucks templates
/* jshint node: true */
var argv = process.argv.slice(2);
var fs = require('fs');
var hem = new (require('hem'))();
hem.compilers.html = function(path) {
var nunjucks = require('nunjucks'),
name = path.split('app/')[1],
opts = {
name: name,
asFunction: true
},
content = fs.readFileSync(path, 'utf8'),
template = nunjucks.precompileString(content, opts);
return 'module.exports = ' + template;
};
hem.exec(argv[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment