Skip to content

Instantly share code, notes, and snippets.

@bstst
Last active August 29, 2015 14:08
Show Gist options
  • Save bstst/03a0805945fc4e142889 to your computer and use it in GitHub Desktop.
Save bstst/03a0805945fc4e142889 to your computer and use it in GitHub Desktop.
working coffee gulp file, with browserify (watchify) and less builders / watchers
gulp = require 'gulp'
coffee = require 'gulp-coffee'
util = require 'gulp-util'
less = require 'gulp-less'
watch = require 'gulp-watch'
livereload = require 'gulp-livereload'
watchify = require 'watchify'
browserify = require 'browserify'
coffeeify = require 'coffeeify'
source = require 'vinyl-source-stream'
path = require 'path'
gulp.task 'coffee-watch', ->
bundler = watchify browserify './src/app.coffee', watchify.args
bundler.transform 'coffeeify'
rebundle = ->
util.log 'Rebundling'
bundler.bundle()
.on 'error', util.log.bind util, 'Browserify error'
.pipe source 'app.js'
.pipe gulp.dest 'public/js'
.pipe livereload auto: false
bundler.on 'update', rebundle
rebundle()
gulp.task 'less', ->
gulp.src './less/main.less'
.pipe less paths: [path.join __dirname, 'less', 'includes']
.pipe gulp.dest './public/css'
.pipe livereload auto: false
gulp.task 'coffee', ->
gulp.src './src/*.coffee'
.pipe coffee()
.pipe gulp.dest 'public/js'
gulp.task 'default', ['coffee', 'less']
gulp.task 'server', ->
livereload.listen()
gulp.task 'watch', ['server', 'coffee-watch', 'less'], ->
watch 'public/**/*.html', (files, cb) ->
livereload.changed()
cb()
watch 'less/**/*.less', (files, cb) ->
gulp.start 'less', cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment