Skip to content

Commit

Permalink
Add browserify recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
baer committed Aug 29, 2014
1 parent a618457 commit 4453283
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/recipes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
* [Split tasks across multiple files](split-tasks-across-multiple-files.md)
* [Using external config file](using-external-config-file.md)
* [Using multiple sources in one task](using-multiple-sources-in-one-task.md)
* [Browserify + Uglify with sourcemaps](browserify-uglify-sourcemaps.md)
44 changes: 44 additions & 0 deletions docs/recipes/browserify-uglify-sourcemap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Browserify + Uglify2 with sourcemaps

[Browserify](http://github.com/substack/node-browserify) has become an important and indispensable
tool but requires being wrapped before working well with gulp. Below is a simple recipe for using
Browserify with transforms and full sourcemaps that resolve to the original individual files.

``` javascript
'use strict';

var browserify = require('browserify');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');

var getBundleName = function () {
var version = require('./package.json').version;
var name = require('./package.json').name;
return version + '.' + name + '.' + 'min';
};

gulp.task('javascript', function() {

var bundler = browserify({
entries: ['./app.js'],
debug: true
});

var bundle = function() {
return bundler
.bundle()
.pipe(source(getBundleName() + '.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
// Add transformation tasks to the pipeline here.
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/js/'));
};

return bundle();
});
```

0 comments on commit 4453283

Please sign in to comment.