-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgulpfile.coffee
173 lines (143 loc) · 3.95 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
pkg = require './package.json'
gulp = require 'gulp'
watch = require 'gulp-watch'
clean = require 'gulp-clean'
plumber = require 'gulp-plumber'
webserver = require 'gulp-webserver'
coffee = require 'gulp-coffee'
concat = require 'gulp-concat'
uglify = require 'gulp-uglify'
minifyCSS = require 'gulp-minify-css'
minifyHtml = require 'gulp-minify-html'
rename = require 'gulp-rename'
header = require 'gulp-header'
gulpFilter = require 'gulp-filter'
sourcemaps = require 'gulp-sourcemaps'
runSequence = require 'run-sequence'
# 路径
paths =
dest : 'dist'
src : 'src'
build : 'build'
# 文件类型
files =
coffee: "#{paths.src}/**/*.coffee"
js : "#{paths.src}/**/*.js"
html : "#{paths.src}/**/*.html"
css : "#{paths.src}/**/*.css"
jpg : "#{paths.src}/**/*.jpg"
png : "#{paths.src}/**/*.png"
gif : "#{paths.src}/**/*.gif"
eot : "#{paths.src}/**/*.eot"
svg : "#{paths.src}/**/*.svg"
ttf : "#{paths.src}/**/*.ttf"
woff : "#{paths.src}/**/*.woff"
otf : "#{paths.src}/**/*.otf"
# 过滤的文件
cssFilter = gulpFilter '**/*.css'
# 开发模式-默认
gulp.task 'default', ->
runSequence 'clean', 'copy', 'css', 'html', 'coffee', 'webserver', 'watch'
# 生成发布
gulp.task 'build', ->
runSequence 'clean', 'copy', 'css', 'html', 'coffee', 'build-copy', 'build-angular', 'build-angular-mobile', 'clean'
gulp.task 'build-copy', ->
gulp.src [
files.css
files.jpg
files.png
files.gif
files.eot
files.svg
files.ttf
files.woff
files.otf
]
.pipe cssFilter
.pipe minifyCSS()
.pipe cssFilter.restore()
.pipe gulp.dest paths.build
# build-angular-mobile
gulp.task 'build-angular-mobile', ->
gulp.src [
"#{paths.dest}/libs/mobileBUGFix.mini.js"
"#{paths.dest}/localResize.ui.js"
"#{paths.dest}/localResize.js"
"#{paths.dest}/localResize.angular.js"
]
.pipe uglify()
.pipe concat 'all.js'
.pipe rename 'localResize.angular.mobile.min.js'
.pipe header """
/**
@Name :localResize.angular.mobile for angular
@version : #{pkg.version}
@Date :#{Date()}
@Blog :think2011.github.io
@Author :#{pkg.author}
@Copyright:#{pkg.author}
**/ \n
"""
.pipe gulp.dest paths.build
# build-angular
gulp.task 'build-angular', ->
gulp.src [
"#{paths.dest}/localResize.ui.js"
"#{paths.dest}/localResize.js"
"#{paths.dest}/localResize.angular.js"
]
.pipe uglify()
.pipe concat 'all.js'
.pipe rename 'localResize.angular.min.js'
.pipe header """
/**
@Name :localResize.angular for angular
@version : #{pkg.version}
@Date :#{Date()}
@Blog :think2011.github.io
@Author :#{pkg.author}
@Copyright:#{pkg.author}
**/ \n
"""
.pipe gulp.dest paths.build
gulp.task 'webserver', ->
gulp.src paths.dest
.pipe webserver
host : '0.0.0.0'
port : 1991
livereload : true
open : false
directoryListing: {enable:true, path: paths.dest}
gulp.task 'watch', ->
watch files.coffee, -> gulp.start 'coffee'
watch files.html, -> gulp.start 'html'
watch files.css, -> gulp.start 'css'
gulp.task 'clean', ->
gulp.src paths.dest
.pipe clean force: true
gulp.task 'copy', ->
gulp.src [
files.js
files.jpg
files.png
files.gif
files.eot
files.svg
files.ttf
files.woff
files.otf
]
.pipe gulp.dest paths.dest
gulp.task 'coffee', ->
gulp.src files.coffee
.pipe plumber()
.pipe sourcemaps.init()
.pipe coffee()
.pipe sourcemaps.write './'
.pipe gulp.dest paths.dest
gulp.task 'html', ->
gulp.src files.html
.pipe gulp.dest paths.dest
gulp.task 'css', ->
gulp.src files.css
.pipe gulp.dest paths.dest