forked from leonidas/gulp-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.coffee
113 lines (91 loc) · 2.82 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
path = require 'path'
gulp = require 'gulp'
gutil = require 'gulp-util'
jade = require 'gulp-jade'
stylus = require 'gulp-stylus'
CSSmin = require 'gulp-minify-css'
browserify = require 'browserify'
watchify = require 'watchify'
source = require 'vinyl-source-stream'
streamify = require 'gulp-streamify'
rename = require 'gulp-rename'
uglify = require 'gulp-uglify'
coffeeify = require 'coffeeify'
ecstatic = require 'ecstatic'
livereload = require 'gulp-livereload'
plumber = require 'gulp-plumber'
prefix = require 'gulp-autoprefixer'
production = process.env.NODE_ENV is 'production'
paths =
scripts:
source: './src/coffee/main.coffee'
destination: './public/js/'
filename: 'bundle.js'
templates:
source: './src/jade/*.jade'
watch: './src/jade/*.jade'
destination: './public/'
styles:
source: './src/stylus/style.styl'
watch: './src/stylus/*.styl'
destination: './public/css/'
assets:
source: './src/assets/**/*.*'
watch: './src/assets/**/*.*'
destination: './public/'
handleError = (err) ->
gutil.log err
gutil.beep()
this.emit 'end'
gulp.task 'scripts', ->
bundle = browserify
entries: [paths.scripts.source]
extensions: ['.coffee']
build = bundle.bundle(debug: not production)
.on 'error', handleError
.pipe source paths.scripts.filename
build.pipe(streamify(uglify())) if production
build
.pipe gulp.dest paths.scripts.destination
gulp.task 'templates', ->
gulp
.src paths.templates.source
.pipe(jade(pretty: not production))
.on 'error', handleError
.pipe gulp.dest paths.templates.destination
.pipe livereload()
gulp.task 'styles', ->
styles = gulp
.src paths.styles.source
.pipe(stylus({set: ['include css']}))
.on 'error', handleError
.pipe prefix 'last 2 versions', 'Chrome 34', 'Firefox 28', 'iOS 7'
styles = styles.pipe(CSSmin()) if production
styles.pipe gulp.dest paths.styles.destination
.pipe livereload()
gulp.task 'assets', ->
gulp
.src paths.assets.source
.pipe gulp.dest paths.assets.destination
gulp.task 'server', ->
require('http')
.createServer ecstatic root: __dirname + '/public'
.listen 9001
gulp.task "watch", ->
livereload.listen()
gulp.watch paths.templates.watch, ['templates']
gulp.watch paths.styles.watch, ['styles']
gulp.watch paths.assets.watch, ['assets']
bundle = watchify
entries: [paths.scripts.source]
extensions: ['.coffee']
bundle.on 'update', ->
build = bundle.bundle(debug: not production)
.on 'error', handleError
.pipe source paths.scripts.filename
build
.pipe gulp.dest paths.scripts.destination
.pipe(livereload())
.emit 'update'
gulp.task "build", ['scripts', 'templates', 'styles', 'assets']
gulp.task "default", ["build", "watch", "server"]