Skip to content

Commit

Permalink
Merge pull request #371 from cpojer/commonjs-export-option
Browse files Browse the repository at this point in the history
Add CommonJS export option for template compilation.
  • Loading branch information
kpdecker committed Nov 25, 2012
2 parents 39832c0 + c3f92c4 commit bd04901
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bin/handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -139,7 +147,7 @@ argv._.forEach(function(template) {
if (!argv.simple) {
if (argv.amd) {
output.push('});');
} else {
} else if (!argv.commonjs) {
output.push('})();');
}
}
Expand Down

0 comments on commit bd04901

Please sign in to comment.