Skip to content

Instantly share code, notes, and snippets.

@diffused
Created March 25, 2015 23:54
Show Gist options
  • Save diffused/23ccf0b4fea063329552 to your computer and use it in GitHub Desktop.
Save diffused/23ccf0b4fea063329552 to your computer and use it in GitHub Desktop.
Gulpfile to transpile ES6 using babel and browserify
// npm install --save-dev gulp gulp-babel babelify through2 gulp-rename gulp-load-plugins
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserify = require('browserify');
var through2 = require('through2');
var babelify = require('babelify');
var srcApp = './src/app.js';
var srcWatchPath = './src/**/*.js'
var distAppPath = './dist';
var distAppFile = 'app.js';
gulp.task('build', function() {
return gulp.src(srcApp)
.pipe(through2.obj(function(file, enc, next) {
browserify(file.path, {
debug: process.env.NODE_ENV === 'development'
})
.transform(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($.rename(distAppFile))
.pipe(gulp.dest(distAppPath));
});
gulp.task('watch', function() {
gulp.watch(srcWatchPath, ['build']);
});
gulp.task('default', ['watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment