lazd/gulp-handlebars — pull request #17 by wbyoung (2014-03-11 23:48:51+00:00)
Title: Abstracting module definition.

### Background

I wanted to create a new plugin, [gulp-ember-emblem](https://github.com/wbyoung/gulp-ember-emblem).

There are [multiple](https://github.com/fuseelements/gulp-ember-handlebars) [forks](https://github.com/silvinci/gulp-emblem) of [gulp-handlebars](https://github.com/lazd/gulp-handlebars). They seem to have been forked at a different point in time, and they haven't been pulling in changes from from _gulp-handlebars_ as changes have been made. That got me thinking… how can I abstract this a bit so that some of the functionality can change more independently.

I came up with [gulp-define-module](https://github.com/wbyoung/gulp-define-module).

### Request

As you'll see from the request, this is a pretty radical change. I'm hoping that we can somehow either collaborate to get this into each of the plugins that forked from the _gulp-handlebars_ repo. And I think this could end up being a better solution for the gulp community as a whole since it will result in more continuity between each of these plugins.

The basic idea here is that module definition, AMD, Node, CommonJS, or just plain browser can be pulled out into its own module. The resulting gulp flow looks something like this:

```javascript
var handlebars = require('gulp-handlebars');
var defineModule = require('gulp-define-module');

gulp.task('templates', function(){
gulp.src(['client/templates/*.hbs'])
.pipe(handlebars())
.pipe(defineModule('node'))
.pipe(gulp.dest('build/templates/'));
});
```

This module also has the possibility of replacing [gulp-declare](https://github.com/lazd/gulp-declare), but I'd probably only recommend that for the simple cases (where you know the namespace already exists).