Skip to content

Instantly share code, notes, and snippets.

@hiddentao
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiddentao/0c9137e72493e3be26ce to your computer and use it in GitHub Desktop.
Save hiddentao/0c9137e72493e3be26ce to your computer and use it in GitHub Desktop.
Gulp + Browserify + Watchify for building JS code
browserify = require 'browserify'
source = require 'vinyl-source-stream2'
uglify = require 'gulp-uglify'
watchify = require 'watchify'
gulp = require 'gulp'
gutil = require 'gulp-util'
gulp.task 'js', ->
_process = (b) ->
b.bundle()
.on 'error', (err) ->
gutil.log(err.stack)
.pipe source('app.js')
.pipe uglify()
.pipe gulp.dest(paths.build.js)
b = browserify(
entries: './src/app.js'
debug: true
cache: {}
packageCache: {}
)
# From http://christianalfoni.github.io/javascript/2014/08/15/react-js-workflow.html
if options.watchify
b = watchify(b)
.on 'update', ->
gutil.log 'Rerunning browserify...'
updateStart = Date.now()
_process(b)
gutil.log '...Done (' + (Date.now() - updateStart) + 'ms)'
# kick-off
_process(b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment