Created
July 25, 2014 02:08
-
-
Save heroicyang/ef3eec8b36e0070b85e1 to your computer and use it in GitHub Desktop.
Browserify task
This file contains hidden or 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
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