Skip to content

Instantly share code, notes, and snippets.

@Problematic
Last active May 28, 2017 16:29
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Problematic/c95444472e6d3c5f8460 to your computer and use it in GitHub Desktop.
Save Problematic/c95444472e6d3c5f8460 to your computer and use it in GitHub Desktop.
Using Babel and Browserify with gulp
var gulp = require('gulp');
var browserify = require('browserify');
var through2 = require('through2');
gulp.task('build', function () {
return gulp.src('./src/main.js')
.pipe(through2.obj(function (file, enc, next) {
browserify(file.path, { debug: process.env.NODE_ENV === 'development' })
.transform(require('babelify'))
.bundle(function (err, res) {
if (err) { return next(err); }
file.contents = res;
next(null, file);
});
}))
.on('error', function (error) {
console.log(error.stack);
this.emit('end');
})
.pipe(require('gulp-rename')('bundle.js'))
.pipe(gulp.dest('./dist'));
});
@cozuya
Copy link

cozuya commented Feb 28, 2015

Thanks, works fine, forgot to require through2 though. Also should mention you can easily get sourcemaps by adding an options argument to line 7 e.g. :

browersify(file.path, {debug: true})

@Problematic
Copy link
Author

Thanks! I made an edit to enable debug mode when NODE_ENV is "development", but as you say, it's easy enough to get them all the time by setting the debug flag to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment