Skip to content

Instantly share code, notes, and snippets.

@itayw
Last active August 29, 2015 14:16
Show Gist options
  • Save itayw/aee4cbaaef5113cb6902 to your computer and use it in GitHub Desktop.
Save itayw/aee4cbaaef5113cb6902 to your computer and use it in GitHub Desktop.
Gulp - build and watch
var watchify = require('watchify');
var browserify = require('browserify');
var paths = {
lib: './www/lib/index.js',
dist: './www/js/'
};
var bundler = browserify(paths.lib, browserify.args);
bundler.transform('brfs');
function watch(){
var watcher= watchify(bundler);
watcher.on('update', bundle); // on any dep update, runs the bundler
watcher.on('log', gutil.log); // output build logs to terminal
bundle();
}
function bundle() {
// add any other browserify options or transforms here
return bundler.bundle()
// log errors if they happen
.on('log', gutil.log)
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('bundle.js'))
// optional, remove if you dont want sourcemaps
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file
.pipe(sourcemaps.write('./')) // writes .map file
//
.pipe(gulp.dest(paths.dist));
}
gulp.task('build', bundle);
gulp.task('watch', watch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment