Skip to content

Instantly share code, notes, and snippets.

@andreapavoni
Created November 28, 2014 10:36
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 andreapavoni/70405c912c0dd0a04597 to your computer and use it in GitHub Desktop.
Save andreapavoni/70405c912c0dd0a04597 to your computer and use it in GitHub Desktop.
Gulp + browserify + coffeelint + bower + ...
gulp = require('gulp')
gutil = require('gulp-util')
browserify = require('gulp-browserify')
coffeelint = require('gulp-coffeelint')
rename = require('gulp-rename')
uglify = require('gulp-uglify')
size = require('gulp-size')
clean = require('gulp-rimraf')
# LOAD ENVs to use with envify
require('dotenv').load()
JS_DEST='./public/js'
JS_BUNDLE='bundle'
BM_BUNDLE='bookmarklet'
gulp.task 'clean', ->
gulp.src([
"#{JS_DEST}/*"
], read: false).pipe clean()
gulp.task 'build-bookmarklet', ->
gulp.src('./client/bookmarklet.coffee', { read: false })
.pipe browserify(
transform: ['coffeeify', 'envify']
extensions: ['.coffee']
)
.on 'error', gutil.log
.pipe rename("#{BM_BUNDLE}.js")
.pipe gulp.dest(JS_DEST)
.pipe size(showFiles: true)
gulp.task 'build-app', ->
gulp.src('./client/app.coffee', { read: false })
.pipe browserify(
transform: ['coffeeify', 'envify', 'debowerify']
extensions: ['.coffee']
)
.on 'error', gutil.log
.pipe rename("#{JS_BUNDLE}.js")
.pipe gulp.dest(JS_DEST)
.pipe size(showFiles: true)
gulp.task 'build', ['lint', 'build-bookmarklet', 'build-app']
gulp.task 'dist', ['clean', 'build'], ->
process.env.NODE_ENV = 'production'
gulp.src("#{JS_DEST}/*.js")
.pipe(uglify())
.pipe(rename(
suffix: ".min"
extname: ".js"
))
.pipe(gulp.dest(JS_DEST))
.pipe(size showFiles: true)
.on("error", gutil.log)
gulp.task 'lint', ->
gulp.src(["./client/**/*.coffee", "./server/**/*.coffee"])
.pipe coffeelint()
.pipe coffeelint.reporter()
.pipe coffeelint.reporter('fail')
gulp.task 'watch', ->
gulp.watch "client/**/*.coffee", ['build']
gulp.task 'default', ['build']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment