Skip to content

Instantly share code, notes, and snippets.

@vojd
Last active August 29, 2015 14:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vojd/a2d277bc161a2674aeaa to your computer and use it in GitHub Desktop.
Save vojd/a2d277bc161a2674aeaa to your computer and use it in GitHub Desktop.
Gulp, browserify, reactify, notify and watchify for coffeescript
# Original https://gist.github.com/Sigmus/9253068
source = require 'vinyl-source-stream'
gulp = require 'gulp'
gutil = require 'gulp-util'
browserify = require 'browserify'
reactify = require 'reactify'
watchify = require 'watchify'
notify = require 'gulp-notify'
paths =
mainFile: 'app.js'
src: './src/'
build: './build/'
dist: './dist/'
# Based on: http://blog.avisi.nl/2014/04/25/how-to-keep-a-fast-build-with-browserify-and-reactjs/
buildScript = (file, watch) ->
rebundle = ->
stream = bundler.bundle()
stream.on("error", notify.onError(
title: "Compile Error"
message: "<%= error.message %>"
)).pipe(source(file)).pipe gulp.dest(paths.build)
props = watchify.args
props.entries = [paths.src + file]
props.debug = true
bundler = (if watch then watchify(browserify(props)) else browserify(props))
bundler.transform reactify
bundler.on "update", ->
rebundle()
gutil.log "Rebundled..."
return
rebundle()
gulp.task "build", ->
buildScript paths.mainFile, false
gulp.task "default", ["build"], ->
buildScript paths.mainFile, true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment