-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.coffee
59 lines (48 loc) · 1.41 KB
/
gulpfile.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
gulp = require 'gulp'
bower = require 'main-bower-files'
concat = require 'gulp-concat'
filter = require 'gulp-filter'
babel = require 'gulp-babel'
browserify = require 'browserify'
source = require 'vinyl-source-stream'
glob = require 'glob'
rename = require 'gulp-rename'
plumber = require 'gulp-plumber'
notify = require 'gulp-notify'
gutil = require 'gulp-util'
watchify = require 'watchify'
paths =
srcFiles: glob.sync('./frontend/javascripts/**/*.{js,jsx,coffee}')
build: './public/'
buildFile: 'bundle.js'
buildScript = (files, watch, dist) ->
buildFile = paths.buildFile
if dist
buildFile = "dist.js"
rebundle = ->
stream = bundler.bundle()
stream.on("error", notify.onError(
title: "Compile Error"
message: "<%= error.message %>"
))
.pipe(source(buildFile))
.pipe gulp.dest(paths.build)
.pipe(notify("success"))
props = watchify.args
props.entries = files
if !dist
props.debug = true
bundler = (if watch then watchify(browserify(props)) else browserify(props))
bundler.transform("babelify", {presets: ["es2015", "react"]})
bundler.on "update", ->
rebundle()
gutil.log "Rebundled..."
gutil.log paths.srcFiles
return
rebundle()
gulp.task "default", ->
buildScript paths.srcFiles, false, false
gulp.task "watch", ["default"], ->
buildScript paths.srcFiles, true, false
gulp.task 'dist', ->
buildScript paths.srcFiles, false, true