Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hexode/ddc97794f643b76665249f01fde95cff to your computer and use it in GitHub Desktop.
Save hexode/ddc97794f643b76665249f01fde95cff to your computer and use it in GitHub Desktop.
watchify example
var browserify = require('browserify');
var watchify = require('watchify');
var reactify = require('reactify');
var gulp = require('gulp');
var handleErrors = require('../util/handleErrors');
var source = require('vinyl-source-stream');
function scripts(watch) {
var bundler, rebundle;
if(watch) {
bundler = watchify('./app/scripts/app.js');
} else {
bundler = browserify('./app/scripts/app.js');
}
bundler.transform(reactify);
rebundle = function() {
var stream = bundler.bundle({debug: true});
stream.on('error', handleErrors);
stream = stream.pipe(source('app.js'));
return stream.pipe(gulp.dest('./build/'));
};
bundler.on('update', rebundle);
return rebundle();
}
gulp.task('browserify-build', function() {
return scripts(false);
});
gulp.task('browserify-watch', function() {
return scripts(true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment