Skip to content

Instantly share code, notes, and snippets.

@wtfil
Last active September 15, 2015 09:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtfil/e346e1d34489b95e5dba to your computer and use it in GitHub Desktop.
Save wtfil/e346e1d34489b95e5dba to your computer and use it in GitHub Desktop.
var browserify = require('browserify');
var watchify = require('watchify');
var gutil = require('gulp-util');
var fs = require('fs')
var files = {
js: {
src: 'path to src',
dst: 'path to dst'
}
};
gulp.task('js-watch', function () {
var args = watchify.args;
args.degub = true;
var bundler = watchify(browserify(files.js.src, args));
bundler.transform('babelify');
bundler.on('update', rebundle);
function onError(e) {
gutil.log(gutil.colors.red(e.message));
}
function rebundle() {
var start = Date.now();
return bundler.bundle()
.on('error', onError)
.on('end', function () {
var time = Date.now() - start;
gutil.log('Building \'' + gutil.colors.green(files.js.src) + '\' in ' + gutil.colors.magenta(time + ' ms'));
})
.pipe(fs.createWriteStream(files.js.dest));
}
rebundle();
});
{
"dependencies": {
"babelify": "^6.1.2",
"browserify": "^10.2.4",
"gulp": "^3.9.0",
"gulp-util": "^3.0.6",
"react": "^0.13.3",
"watchify": "^3.2.3",
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment