 
 jsBundleFile = 'app-js.js'
 
-gulp.task 'js', ->
-  bundler.bundle()
-    .pipe(source(jsBundleFile))
-    .pipe(buffer())
-    .pipe(gulpif(!argv.production, sourcemaps.init({loadMaps: true})))
-      .pipe(gulpif(argv.production, uglify()))
-    .pipe(gulpif(!argv.production, sourcemaps.write('./')))
-    .pipe(gulp.dest('./dist/assets/js'))
+gulp.task 'browserify', ->
+  watcher = watchify(bundler)
+
+  watcher.on 'update', ->
+    updateStart = Date.now()
+    console.log('Browserify started')
+    watcher.bundle()
+      .pipe(source(jsBundleFile))
+        ## uglify
+      .pipe(gulp.dest('./dist/assets/js'))
+      .pipe(connect.reload())
+    console.log('Browserify ended', (Date.now() - updateStart) + 'ms')
+  .bundle()
+  .pipe(source(jsBundleFile))
+  .pipe(gulp.dest('./dist/assets/js'))
+  .pipe(connect.reload())
 
 gulp.task 'sass', ->
   gulp.src ['./app/**/*.scss']

gulp = require 'gulp'
gutil = require 'gulp-util'
gulpif = require 'gulp-if'
assign = require 'lodash.assign'
minifycss = require 'gulp-minify-css'
sass = require 'gulp-sass'
source = require 'vinyl-source-stream'

argv = require('yargs').argv
assign = require 'lodash.assign'
autoprefixer = require 'gulp-autoprefixer'
browserify = require 'browserify'
buffer = require 'vinyl-buffer'
