-
Notifications
You must be signed in to change notification settings - Fork 136
/
Gruntfile.js
executable file
·150 lines (137 loc) · 3.33 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
// 包装函数
module.exports = function(grunt) {
// 任务配置,所有插件的配置信息
grunt.initConfig({
//获取 package.json 的信息
pkg: grunt.file.readJSON('package.json'),
// uglify插件的配置信息
uglify: {
options: {
stripBanners: true,
banner: '/*! <%=pkg.name%>.js <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'src/js/<%=pkg.name%>.js',
dest: 'dist/js/<%=pkg.name%>.min.js'
}
},
//less插件的配置信息
less: {
boxFlex: {
src: 'src/css/parts/box-flex.less',
dest: 'src/css/parts/box-flex.css'
},
editorContainer: {
src: 'src/css/parts/txt.less',
dest: 'src/css/parts/txt.css'
},
menuContainer: {
src: 'src/css/parts/menu-container.less',
dest: 'src/css/parts/menu-container.css'
},
modalContainer: {
src: 'src/css/parts/modal.less',
dest: 'src/css/parts/modal.css'
}
},
//cssmin插件的配置信息
cssmin: {
options: {
stripBanners: true,
banner: '/*! <%=pkg.name%>.css <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'src/css/<%=pkg.name%>.css',
dest: 'dist/css/<%=pkg.name%>.min.css'
}
},
//jshint插件的配置信息'
jshint:{
build: [ 'Gruntfile.js', 'src/js/*.js' ],
options: {
jshintrc: '.jshintrc'
}
},
//concat插件的配置信息
concat: {
css:{
src: 'src/css/parts/*.css',
dest: 'src/css/<%=pkg.name%>.css'
},
js:{
src: 'src/js/parts/*.js',
dest: 'src/js/<%=pkg.name%>.js'
}
},
//copy插件的配置信息
copy: {
main: {
files:[
//js
{
expand: true,
flatten: true,
src: ['src/js/*.js'],
dest: 'dist/js/',
filter: 'isFile'
},
//css
{
expand: true,
flatten: true,
src: ['src/css/*.css'],
dest: 'dist/css/',
filter: 'isFile'
}
]
}
},
// watch插件的配置信息
watch: {
js: {
files: [
'src/js/parts/*.js'
],
tasks: [
'concat',
'jshint',
'uglify',
'copy'
],
options: { spawn: false}
},
css:{
files: [
'src/css/parts/*.less',
'src/css/ico.css'
],
tasks: [
'less',
'concat',
'cssmin',
'copy'
],
options: { spawn: false}
}
}
});
// 告诉grunt我们将使用插件
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
// 告诉grunt当我们在终端中输入grunt时需要做些什么(注意先后顺序)
grunt.registerTask('default', [
//注意下面注册任务时的前后顺序
'less',
'concat',
'jshint',
'uglify',
'cssmin',
'copy',
'watch'
]);
};