Skip to content

Instantly share code, notes, and snippets.

@Problematic

Problematic/gulpfile.js

Last active May 28, 2017
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@cozuya 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

This comment has been minimized.

Copy link
Owner Author

@Problematic Problematic commented Mar 1, 2015

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