Created
March 25, 2015 23:54
-
-
Save diffused/23ccf0b4fea063329552 to your computer and use it in GitHub Desktop.
Gulpfile to transpile ES6 using babel and browserify
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
// 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