Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
gulp = require 'gulp'
watchify = require 'watchify'
browserify = require 'browserify'
source = require 'vinyl-source-stream'
buffer = require 'vinyl-buffer'
gutil = require 'gulp-util'
assign = require 'lodash.assign'
rename = require 'rename'
EXTERNALS = [
{'require': 'jquery', expose: '$'},
]
opts =
entries: ['./src/index.coffee']
debug: true
extensions: ['.js', '.coffee']
bundleExternal: false
b = watchify(browserify(assign {}, watchify.args, opts))
.transform("coffeeify")
.plugin("minifyify", {
output: 'js/index.js.map'
map: 'index.js.map'
})
bundle = ->
b.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('index.js'))
.pipe(buffer())
.pipe(gulp.dest('./js'))
b.on 'update', bundle
b.on 'log', gutil.log
gulp.task 'libs', ->
vb = browserify('./src/vendor.coffee', debug: true)
.plugin("minifyify", output: 'js/vendor.js.map', map: 'index.js.map')
EXTERNALS.forEach (x) ->
if x.expose?
vb.require x.require, expose: x.expose
b.external x.require, expose: x.expose
else
vb.require x.require
b.external x.require
watchify(vb)
.bundle()
.pipe(source('vendor.js'))
.pipe(gulp.dest("./js"))
gulp.task 'default', ['libs'], bundle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment