Skip to content

Instantly share code, notes, and snippets.

@spion
Last active December 15, 2015 04:18
Show Gist options
  • Select an option

  • Save spion/5200049 to your computer and use it in GitHub Desktop.

Select an option

Save spion/5200049 to your computer and use it in GitHub Desktop.
browserify-jade-v2
// Example browserify transform which precompiles Jade
// templates including them in the bundle, allowing you
// to use:
// var tmpl = require('./templates/template.jade');
//
// Supports layouts and blocks
//
// requirements:
// npm install jade through
//
// command line:
// browserify -t ./browserify-v2.jade.js main.js -o bundle.js
var through = require('through'),
jade = require('jade');
module.exports = function (file) {
if (!/\.jade$/.test(file)) return through();
var data = '';
return through(write, end);
function write (buf) { data += buf }
function end () {
var result = compile(file, data);
this.queue(result);
this.queue(null);
}
};
module.exports.root = null;
function compile(file, tmpl) {
var fn = jade.compile(tmpl, {
client: true,
filename:true,
path: __dirname
});
return ["var jade = require('jade/lib/runtime.js');",
'module.exports=',fn.toString()].join('');
}
@OliverJAsh

Copy link
Copy Markdown

Thanks for sharing this! Using it myself now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment