-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
296 lines (249 loc) · 10.8 KB
/
Gruntfile.js
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
module.exports = function(grunt){
//自动监控任务配置
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
//自动检测文件变化 刷新浏览器
watch:{
client:{
files:['dev/*.html','dev/lib/*.js','dev/lib/**/*.js','dev/lib/**/*.css','dev/lib/**/*.png','dev/lib/**/*.gif','dev/lib/**/*.jpg','dev/partials/*'],
options:{
livereload:true
}
}
},
requirejs:{
build:{
options:{
// app顶级目录,非必选项。如果指定值,baseUrl则会以此为相对路径
appDir:'dev/',
// 模块根目录。默认情况下所有模块资源都相对此目录。
// 若该值未指定,模块则相对build文件所在目录。
// 若appDir值已指定,模块根目录baseUrl则相对appDir。
baseUrl:'lib',
// 指定输出目录,若值未指定,则相对 build 文件所在目录
dir:'build/',
mainConfigFile: 'dev/lib/app.js',
paths:{
'public':'app/public',
'jquery':'vender/jquery.min',
'fastclick':'vender/fastclick',
'highcharts':'vender/highcharts',
'af.actionsheet':'plugin/af.actionsheet',
'af.animation':'plugin/af.animation',
'af.touchEvents':'plugin/af.touchEvents',
'af.popup':'plugin/af.popup',
'af.drawer':'plugin/af.drawer',
'af.toast':'plugin/af.toast',
'af.animateheader':'plugin/af.animateheader',
'af.splashscreen':'plugin/af.splashscreen',
'af.swipereveal':'plugin/af.swipereveal',
'af.lockscreen':'plugin/af.lockscreen',
//自定义模块
'juiRechargeSelectCardLib':'app/juiRechargeSelectCardLib'
},
modules: [
{
name: 'app',
include:[
'jquery','fastclick', 'af.shim', 'af.ui', 'af.actionsheet', 'af.touchEvents',
'af.animation', 'af.popup', 'af.drawer', 'af.toast', 'af.animateheader',
'af.splashscreen', 'af.swipereveal', 'highcharts'
],
//级联依赖
excludeShallow: [
"public"
]
}
],
// 在 RequireJS 2.0.2 中,输出目录的所有资源会在 build 前被删除
// 值为 true 时 rebuild 更快,但某些特殊情景下可能会出现无法预料的异常
keepBuildDir: true,
// JS 文件优化方式,目前支持以下几种:
// uglify: (默认) 使用 UglifyJS 来压缩代码
// closure: 使用 Google's Closure Compiler 的简单优化模式
// closure.keepLines: 使用 closure,但保持换行
// none: 不压缩代码
optimize:'uglify',
// 使用 UglifyJS 时的可配置参数
// See https://github.com/mishoo/UglifyJS for the possible values.
uglify:{
toplevel:true,
ascii_only:true,
beautify:false,
max_line_length:1000,
no_mangle:true,
preserveComments:false,
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */'
},
// CSS 优化方式,目前支持以下几种:
// none: 不压缩,仅合并
// standard: 标准压缩,移除注释、换行,以及可能导致 IE 解析出错的代码
// standard.keepLines: 除标准压缩外,保留换行
// standard.keepComments: 除标准压缩外,保留注释 (r.js 1.0.8+)
// standard.keepComments.keepLines: 除标准压缩外,保留注释和换行 (r.js 1.0.8+)
optimizeCss:'standard',
// 是否忽略 CSS 资源文件中的 @import 指令
cssImportIgnore:null,
// 处理所有的文本资源依赖项,从而避免为加载资源而产生的大量单独xhr请求
inlineText:true,
// 是否开启严格模式
// 由于很多浏览器不支持 ES5 的严格模式,故此配置默认值为 false
useStrict: false,
// 不优化某些文件
fileExclusionRegExp: /^(r|build)\.js$/,
// 默认保留模块的 license 注释
preserveLicenseComments: false,
shim:{
'fastclick':{
exports:'fastclick'
},
'highcharts':{
deps:['jquery'],
exports:'highcharts'
},
'af.shim':{
deps:['jquery'],
exports:'af.shim'
},
'af.ui':{
deps:['jquery'],
exports:'af.ui'
},
'af.actionsheet':{
deps:['jquery','af.ui'],
exports:'af.actionsheet'
},
'af.animation':{
deps:['jquery','af.ui'],
exports:'af.animation'
},
'af.touchEvents':{
deps:['jquery','af.ui'],
exports:'af.touchEvents'
},
'af.popup':{
deps:['jquery','af.ui'],
exports:'af.popup'
},
'af.drawer':{
deps:['jquery','af.ui'],
exports:'af.drawer'
},
'af.toast':{
deps:['jquery','af.ui'],
exports:'af.toast'
},
'af.animateheader':{
deps:['jquery','af.ui'],
exports:'af.animateheader'
},
'af.splashscreen':{
deps:['jquery','af.ui'],
exports:'af.splashscreen'
},
'af.swipereveal':{
deps:['jquery','af.ui'],
exports:'af.swipereveal'
},
'af.lockscreen':{
deps:['jquery','af.ui'],
exports:'af.lockscreen'
}
}
}
}
},
//css压缩
cssmin: {
target: {
files: [{
expand: true,
cwd: 'dev/lib/css',
src: ['af.ui.css','icons.min.css','app.css'],
dest: 'build/lib/css',
ext: '.min.css'
}]
}
},
//压缩html文件
htmlmin:{
dist:{
options:{
removeComments: true,
collapseWhitespace: true
},
files:{
'build/index.html':'dev/index.html',
'build/partials/subnav.html':'dev/partials/subnav.html'
}
}
},
//ios工程www目录
iosWebRoot:'/Users/xuhui/workspace/development/jyx/platforms/ios/www',
//发布html
copy:{
main:{
files:[
{expand:true,cwd:'build/',src:['*','**/*','**/**/*'],dest:'<%= iosWebRoot %>'}
]
}
},
imagemin: {
options:{
optimizationLevel:5
},
dynamic: {
files: [{
expand: true,
cwd: 'dev/lib/img',
src: ['*.{png,jpg,gif}','**/*.{png,jpg,gif}'],
dest: 'build/lib/img/'
}]
}
},
//替换html中资源的引用路径
htmlbuild: {
dist: {
src: 'build/index.html',
dest: 'build/',
options: {
beautify: true,
//prefix: '',
relative: true,
styles: {
bundle: [
'lib/css/icons.min.css',
'lib/css/af.ui.css',
'lib/css/app.css'
],
test: 'lib/css/jinyixing.css'
}
}
}
},
clean: {
build_before:{
all:["build/*","<%= iosWebRoot %>/index.html","<%= iosWebRoot %>/lib","<%= iosWebRoot %>/partials"]
},
//清理合并后多余的文件
build_after:{
js: ["build/lib/plugin" , "build/lib/vender","build/lib/af.ui.js", "build/lib/af.shim.js"],
css:["build/lib/css/*.css","!build/lib/css/jinyixing.css"],
other:["build/build.txt","build/lib/img",'<%= iosWebRoot %>/build.txt']
}
}
});
//加载插件
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-html-build');
//自定义任务
grunt.registerTask('live',['watch']);
grunt.registerTask('default',['clean:build_before','htmlmin','requirejs','copy','clean:build_after']);
}