Skip to content

Commit

Permalink
add recipe to show correct usage of transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Apr 1, 2015
1 parent 14e93eb commit 064e2fc
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions docs/recipes/browserify-transforms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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.

See also: the [Combining Streams to Handle Errors](https://github.com/gulpjs/gulp/blob/master/docs/recipes/combining-streams-to-handle-errors.md) recipe for handling errors with browserify or uglify in your stream.

``` javascript
'use strict';

var browserify = require('browserify');
var gulp = require('gulp');
var transform = require('vinyl-transform');
var gutil = require('gulp-util');
var reactify = require('reactify');

gulp.task('javascript', function () {
// set up the browserify instance on a task basis
var b = browserify({
debug: true,
// defining transforms here will avoid crashing your stream
transform: [reactify]
});
// transform regular node stream to gulp (buffered vinyl) stream
var browserified = transform(function(filename) {
b.add(filename);
return b.bundle();
});

return gulp.src('./app.js')
.pipe(browserified)
.pipe(sourcemaps.init({loadMaps: true}))
// Add transformation tasks to the pipeline here.
.pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/js/'));
});
```

0 comments on commit 064e2fc

Please sign in to comment.