$ gulp browserify# add watch tasks
gulp.task 'watch', ['setWatch', 'browserify'], ->
# ...then
$ gulp watch| gulp = require 'gulp' | |
| browserify = require 'browserify' | |
| watchify = require 'watchify' | |
| source = require 'vinyl-source-stream' | |
| colors = require 'colors' | |
| files = [ | |
| { | |
| input : ['./src/scripts/main.coffee'] | |
| output : 'main.js' | |
| extensions : ['.coffee'] | |
| destination: './app/scripts/' | |
| } | |
| { | |
| input : ['./src/scripts/profile.coffee'] | |
| output : 'profile.js' | |
| extensions : ['.coffee'] | |
| destination: './app/scripts/' | |
| } | |
| ] | |
| createBundle = (options) -> | |
| bundleMethod = if global.isWatching then watchify else browserify | |
| bundler = bundleMethod | |
| entries : options.input | |
| extensions: options.extensions | |
| rebundle = -> | |
| startTime = new Date().getTime() | |
| bundler.bundle | |
| debug: true | |
| .on 'error', -> | |
| console.log arguments | |
| .pipe(source(options.output)) | |
| .pipe gulp.dest(options.destination) | |
| .on 'end', -> | |
| time = (new Date().getTime() - startTime) / 1000 | |
| console.log "#{options.output.cyan} was browserified: #{(time + 's').magenta}" | |
| if global.isWatching | |
| bundler.on 'update', rebundle | |
| rebundle() | |
| createBundles = (bundles) -> | |
| bundles.forEach (bundle) -> | |
| createBundle | |
| input : bundle.input | |
| output : bundle.output | |
| extensions : bundle.extensions | |
| destination: bundle.destination | |
| gulp.task 'browserify', -> | |
| createBundles files |
| gulp = require 'gulp' | |
| gulp.task 'setWatch', -> | |
| global.isWatching = true |