Created
April 27, 2015 18:24
-
-
Save maximilianschmitt/80a0e1f0c8cb7a3301d6 to your computer and use it in GitHub Desktop.
Using watchify with gulp
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
'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