Last active
December 10, 2015 15:28
-
-
Save thlorenz/4454557 to your computer and use it in GitHub Desktop.
A browserify plugin that precompiles handlebars templates .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function handlebarify(bundle) { | |
var precompile = require('handlebars').precompile; | |
function handlebarsPlugin(body, file) { | |
return 'var Handlebars = require(\'handlebars\');\nmodule.exports = ' + precompile(body) + ';'; | |
} | |
// browserify doesn't allow passing an array of extensions, so we register each separately | |
bundle.register('.handlebars', handlebarsPlugin); | |
bundle.register('.hbs', handlebarsPlugin); | |
} | |
// use as follows | |
var bundled = browserify({ debug: true }) | |
.use(handlebarify) | |
.addEntry('myentry.js') | |
.bundle(); |
Ok, I'll add that in and possibly will include a way to have your helpers included, although they could also be required as separate modules.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copying @domenic's comment from the anonymous gist:
Domenic: