forked from gulpjs/gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add recipe to show correct usage of transforms
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/')); | ||
}); | ||
``` |