Skip to content

Instantly share code, notes, and snippets.

@steverandy
Created February 3, 2015 03:41
Show Gist options
  • Save steverandy/63694b5ce016fcdc8d16 to your computer and use it in GitHub Desktop.
Save steverandy/63694b5ce016fcdc8d16 to your computer and use it in GitHub Desktop.
gulp.task "bundle-scripts", ->
delete require.cache[require.resolve "./assets/bundles"]
bundles = require "./assets/bundles"
scripts = _.filter _.keys(bundles), (filename) ->
filename.indexOf(".js") >= 0
merge _.map scripts, (filename) ->
if filename.indexOf(".js") is -1 then return
coffeeFilter = filter "**/*.coffee"
stream = gulp.src bundles[filename]
.pipe coffeeFilter
.pipe cache coffee()
.on "error", (err) ->
console.log err.toString()
@emit "end"
.pipe coffeeFilter.restore()
.pipe concat filename
if process.env.NODE_ENV is "production"
stream.pipe uglify()
stream.pipe gulp.dest "public/assets/bundles"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment