gruntjs/grunt-contrib-handlebars

CommonJS auto-require Handlebars

Opened this issue · 2 comments

Is there a reason for not having an auto-require option for Handlebars when using the CommonJS compiled version?

For example:

options: {
  namespace: false,
  commonjs: true,
  require: 'handlebars'
}

This would add a var Handlebars = require('handlebars'); to the compiled template module, so the user doesn't have to require and passthrough the Handlebars library in every module that needs templates.

Current usage:

var Handlebars = require('handlebars');
var Templates = require('./templates')(Handlebars);

Proposed change would allow:

var Templates = require('./templates');

Am I missing something, or would this have a decent use case? I'd be happy to contribute, just wanted to make sure I'm not missing something that already exists.

+1

This should be a default behavior for commonjs. I'd argue that an option is unnecessary (namespace should probably also default to false for commonjs too).

Sent a pull request #91.