Skip to content

Instantly share code, notes, and snippets.

@maximilianschmitt
Created April 27, 2015 18:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximilianschmitt/80a0e1f0c8cb7a3301d6 to your computer and use it in GitHub Desktop.
Save maximilianschmitt/80a0e1f0c8cb7a3301d6 to your computer and use it in GitHub Desktop.
Using watchify with gulp
'use strict';
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var notifier = require('stream-notifier');
var watchify = require('watchify');
gulp.task('browserify', function() {
var bundler = browserify('./src/main')
var bundle = compileBundle(bundler);
return bundle();
});
gulp.task('watchify', function() {
var opts = watchify.args;
opts.debug = true;
var bundler = watchify(browserify('./src/main', opts));
var bundle = compileBundle(bundler)
bundler.on('update', bundle);
return bundle();
});
function compileBundle(bundler) {
return function() {
var n = notifier('browserify');
return bundler
.bundle()
.on('error', n.error)
.pipe(source('app.js'))
.pipe(gulp.dest('dist'))
.on('end', n.end);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment