From c3f92c402e2ce1c5d31be9c5e67b2abab4a5f81d Mon Sep 17 00:00:00 2001 From: cpojer Date: Thu, 22 Nov 2012 12:07:58 +0100 Subject: [PATCH] Add CommonJS export option for template compilation. --- bin/handlebars | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/handlebars b/bin/handlebars index 7a2fc1cac..dd6e07118 100755 --- a/bin/handlebars +++ b/bin/handlebars @@ -12,11 +12,17 @@ var optimist = require('optimist') 'description': 'Exports amd style (require.js)', 'alias': 'amd' }, + 'c': { + 'type': 'string', + 'description': 'Exports CommonJS style, path to Handlebars module', + 'alias': 'commonjs', + 'default': null + }, 'h': { 'type': 'string', 'description': 'Path to handlebar.js (only valid for amd-style)', 'alias': 'handlebarPath', - 'default': '' + 'default': '' }, 'k': { 'type': 'string', @@ -91,6 +97,8 @@ var output = []; if (!argv.simple) { if (argv.amd) { output.push('define([\'' + argv.handlebarPath + 'handlebars\'], function(Handlebars) {\n'); + } else if (argv.commonjs) { + output.push('var Handlebars = require("' + argv.commonjs + '");'); } else { output.push('(function() {\n'); } @@ -139,7 +147,7 @@ argv._.forEach(function(template) { if (!argv.simple) { if (argv.amd) { output.push('});'); - } else { + } else if (!argv.commonjs) { output.push('})();'); } }