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']); |
This was based off another Gist but I lost the link 😦 I would have liked to attribute and link
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