pyar6329
5/25/2015 - 12:10 PM

gulpfile.coffee

gulpfile.coffee

gulp = require 'gulp'
plumber = require 'gulp-plumber'
coffee = require 'gulp-coffee'
coffee_react = require 'gulp-cjsx'
watchify = require 'gulp-watchify'
rename = require 'gulp-rename'
uglify = require 'gulp-uglify'
sourcemaps = require 'gulp-sourcemaps'
buffer = require 'vinyl-buffer'

gulp.task 'default', ['build']
gulp.task 'build', [
  'build:coffee',
  'build:cjsx'
]

gulp.task 'build:coffee', ->
  gulp
    .src 'src/**/*.coffee'
    .pipe plumber()
    .pipe coffee()
    .pipe gulp.dest('lib')

gulp.task 'build:cjsx', ->
  gulp
    .src 'src/**/*.cjsx'
    .pipe plumber()
    .pipe coffee_react()
    .pipe gulp.dest('lib')

watching = false
gulp.task 'enable-watch-mode', -> watching = true
gulp.task 'browserify', watchify (watchify) ->
  gulp
    .src 'lib/main.js'
    .pipe watchify
      watch: watching
      debug: true
    .pipe buffer()
    .pipe sourcemaps.init
      loadMaps: true
    .pipe uglify()
    .pipe rename('bundle.js')
    .pipe sourcemaps.write('./')
    .pipe gulp.dest('public/js')

gulp.task 'watchify', ['enable-watch-mode', 'browserify']
gulp.task 'watch', ['build', 'enable-watch-mode', 'watchify'], ->
  gulp.watch 'src/**/*.coffee', ['build:coffee']
  gulp.watch 'src/**/*.cjsx', ['build:cjsx']