Created
March 30, 2016 16:58
-
-
Save billgloff/c66b9be9f7b1fe556282fcf1ebda34c8 to your computer and use it in GitHub Desktop.
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
var fs = require('fs'); | |
var path = require('path'); | |
var source = require('vinyl-source-stream'); | |
var gulp = require('gulp'); | |
var gutil = require('gulp-util'); | |
var browserify = require('browserify'); | |
var watchify = require('watchify'); | |
var glob = require('glob'); | |
var source = require('vinyl-source-stream'); | |
var es = require('event-stream'); | |
var buffer = require('vinyl-buffer'); | |
var config = require('../config').browserify; | |
var lrload = require('livereactload'); | |
var watch; | |
gulp.task('browserify-nowatch', function(done) { | |
watch = false; | |
return browserifyWork(done); | |
}); | |
gulp.task('browserify', function(done) { | |
watch = true; | |
return browserifyWork(done); | |
}); | |
function browserifyWork(done) { | |
function bundle(bundler, entry) { | |
return bundler.bundle() | |
.on('error', function(err) { | |
gutil.log(gutil.colors.red('\n**********\nBROWSERIFY ERROR:')); | |
gutil.log(err); | |
gutil.log(gutil.colors.red('\n**********')); | |
this.emit('end'); | |
//process.exit(1); | |
}) | |
.pipe(source(path.basename(entry))) | |
.pipe(gulp.dest(config.dest)); | |
} | |
glob(config.src, function(err, files) { | |
if (err) { | |
done(err); | |
} | |
var tasks = files.map(function(entry) { | |
var b = browserify({ | |
cache: {}, | |
packageCache: {}, | |
entries: [entry], | |
transform: config.settings.transform, | |
plugin: [ lrload ], | |
debug: config.debug, | |
extensions: config.extensions | |
}); | |
if (watch) { | |
var w = watchify(b); | |
w.on('log', gutil.log); | |
w.on('update', function() { | |
gutil.log('Bundler update event fired for entry: ' + entry); | |
bundle(w, entry); | |
}); | |
} | |
return bundle(b, entry); | |
}); | |
es.merge(tasks).on('end', done); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment