-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.coffee
88 lines (79 loc) · 2.18 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
'use strict'
gulp = require 'gulp'
gp = (require 'gulp-load-plugins') lazy: false
path = require 'path'
browserify = require 'browserify'
source = require 'vinyl-source-stream'
# HTML
gulp.task 'html', ->
gulp.src 'app/index.jade'
.pipe gp.plumber()
.pipe gp.jade locals: pageTitle: 'Famo.us built with Gulp'
.pipe gulp.dest 'www'
# JS
gulp.task 'js', ->
browserify
entries: ['./app/js/main.coffee']
extensions: ['.coffee', '.js']
.transform 'coffeeify'
.transform 'deamdify'
.transform 'debowerify'
.transform 'uglifyify'
.bundle()
# Pass desired file name to browserify with vinyl
.pipe source 'main.js'
# Start piping stream to tasks!
.pipe gulp.dest 'www/js'
# CSS
gulp.task 'css', ->
gulp.src 'app/css/*.sass'
.pipe gp.plumber()
.pipe gp.rubySass style: 'compressed', loadPath: ['bower_components', '.']
.pipe gp.cssmin keepSpecialComments: 0
.pipe gp.autoprefixer 'last 1 version'
.pipe gulp.dest 'www/css'
# Images
gulp.task 'img', ->
gulp.src ['app/img/*.jpg', 'app/img/*.png']
.pipe gp.cache gp.imagemin
optimizationLevel: 3
progressive: true
interlaced: true
.pipe gulp.dest 'www/img'
# Clean
gulp.task 'clean', ->
gulp.src ['www', 'tmp'], read: false
.pipe gp.clean force: true
# Build
gulp.task 'build', ['html', 'js', 'css']
# Default task
gulp.task 'default', ['clean'], -> gulp.start 'build'
# Connect
gulp.task 'connect', ['default'], ->
gp.connect.server
root: 'www'
port: 9000
livereload: true
# Watch
gulp.task 'watch', ['connect'], ->
gulp.watch 'app/**/*', read:false, (event) ->
ext = path.extname event.path
taskname = null
reloadasset = null
switch ext
when '.jade', '.md', '.svg'
taskname = 'html'
reloadasset = 'www/index.html'
when '.sass'
taskname = 'css'
reloadasset = 'www/css/main.css'
when '.coffee', '.js'
taskname = 'js'
reloadasset = 'www/js/main.js'
else
taskname = 'img'
reloadasset = "www/img/#{path.basename event.path}"
gulp.task 'reload', [taskname], ->
gulp.src reloadasset
.pipe gp.connect.reload()
gulp.start 'reload'