Last active
May 28, 2017 16:29
-
-
Save Problematic/c95444472e6d3c5f8460 to your computer and use it in GitHub Desktop.
Using Babel and Browserify with gulp
This file contains hidden or 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
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')); | |
}); |
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
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. :