Skip to content

Instantly share code, notes, and snippets.

@heroicyang
Created July 25, 2014 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save heroicyang/ef3eec8b36e0070b85e1 to your computer and use it in GitHub Desktop.
Save heroicyang/ef3eec8b36e0070b85e1 to your computer and use it in GitHub Desktop.
Browserify task
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var watchify = require('watchify');
gulp.task('setWatch', function() {
global.isWatching = true;
});
gulp.task('browserify', function() {
var bundleMethod = global.isWatching ? watchify : browserify;
var bundler = bundleMethod({
entries: ['./src/js/app.coffee'],
extensions: ['coffee']
});
var bundle = function() {
return bundler
.bundle({debug: true})
.pipe(source('app.js'))
.pipe(gulp.dest('./build/'))
};
if(global.isWatching) {
bundle.on('update', bundle);
}
return bundle();
});
gulp.task('watch', ['setWatch', 'browserify'], function() {
// ...
});
gulp.task('default', ['watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment