-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
84 lines (78 loc) · 2.22 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
module.exports=function (grunt) {
//配置
grunt.initConfig({
pkg:grunt.file.readJSON('package.json'),
//检查Style CSS语法
csslint:{
src:['public/stylesheets/*.css']
},
//合并CSS文件
concat:{
css:{
src:['public/stylesheets/*.css'],
//根据目录下文件情况配置
dest:'public/stylesheets/dist/<%=pkg.name%>.css'
}
},
//压缩style CSS文件为 .min.css
cssmin:{
options:{
//移出CSS文件中的所有注释
keepSpecialComments:0
},
minify:{
expand:true,
cwd:'public/stylesheets/dist',
src:['<%=pkg.name%>.css'],
dest:'public/stylesheets/dist',
ext:'.min.css'
}
},
//检查JS语法
jshint:{
all:[
'Gruntfile.js',
'public/javascript/*.js'
]
},
//压缩JS文件
uglify:{
build:{
src:'public/javascript/*.js',
dest:'public/javascript/dist/<%=pkg.name%>.min.js'
}
},
//监控
watch:{
css:{
files:'public/stylesheets/*.css',
tasks:['csslint'], //只监控csslint语法
options:{
spawn:false
}
},
scripts:{
files:'public/javascript/*.js',
tasks:['jshint'],
options:{
spawn:false
}
}
}
});
//另一种加载插件写法:通过数组遍历....
[
'grunt-contrib-csslint',
'grunt-contrib-concat',
'grunt-contrib-cssmin',
'grunt-contrib-jshint',
'grunt-contrib-uglify',
'grunt-contrib-watch'
].forEach(function (task){
grunt.loadNpmTasks(task);
});
//默认任务
grunt.registerInitTask('default',['concat','cssmin','uglify']);
//静态任务用于前端静态资源
grunt.registerInitTask('static',['csslint','jshint']);
};