8
8
// 'test/spec/**/*.js'
9
9
10
10
module . exports = function ( grunt ) {
11
+
12
+ // Load grunt tasks automatically
11
13
require ( 'load-grunt-tasks' ) ( grunt ) ;
14
+
15
+ // Time how long tasks take. Can help when optimizing build times
12
16
require ( 'time-grunt' ) ( grunt ) ;
13
17
18
+ // Define the configuration for all the tasks
14
19
grunt . initConfig ( {
20
+
21
+ // Project settings
15
22
yeoman : {
16
23
// configurable paths
17
24
app : require ( './bower.json' ) . appPath || 'app' ,
18
25
dist : 'dist'
19
26
} ,
27
+
28
+ // Watches files for changes and runs tasks based on the changed files
20
29
watch : {
21
30
coffee : {
22
31
files : [ '<%%= yeoman.app %>/scripts/{,*/}*.coffee' ] ,
@@ -49,17 +58,8 @@ module.exports = function (grunt) {
49
58
]
50
59
}
51
60
} ,
52
- autoprefixer : {
53
- options : [ 'last 1 version' ] ,
54
- dist : {
55
- files : [ {
56
- expand : true ,
57
- cwd : '.tmp/styles/' ,
58
- src : '{,*/}*.css' ,
59
- dest : '.tmp/styles/'
60
- } ]
61
- }
62
- } ,
61
+
62
+ // The actual grunt server settings
63
63
connect : {
64
64
options : {
65
65
port : 9000 ,
@@ -92,6 +92,20 @@ module.exports = function (grunt) {
92
92
}
93
93
}
94
94
} ,
95
+
96
+ // Make sure code styles are up to par and there are no obvious mistakes
97
+ jshint : {
98
+ options : {
99
+ jshintrc : '.jshintrc' ,
100
+ reporter : require ( 'jshint-stylish' )
101
+ } ,
102
+ all : [
103
+ 'Gruntfile.js' ,
104
+ '<%%= yeoman.app %>/scripts/{,*/}*.js'
105
+ ]
106
+ } ,
107
+
108
+ // Empties folders to start fresh
95
109
clean : {
96
110
dist : {
97
111
files : [ {
@@ -105,16 +119,21 @@ module.exports = function (grunt) {
105
119
} ,
106
120
server : '.tmp'
107
121
} ,
108
- jshint : {
109
- options : {
110
- jshintrc : '.jshintrc' ,
111
- reporter : require ( 'jshint-stylish' )
112
- } ,
113
- all : [
114
- 'Gruntfile.js' ,
115
- '<%%= yeoman.app %>/scripts/{,*/}*.js'
116
- ]
122
+
123
+ // Add vendor prefixed styles
124
+ autoprefixer : {
125
+ options : [ 'last 1 version' ] ,
126
+ dist : {
127
+ files : [ {
128
+ expand : true ,
129
+ cwd : '.tmp/styles/' ,
130
+ src : '{,*/}*.css' ,
131
+ dest : '.tmp/styles/'
132
+ } ]
133
+ }
117
134
} ,
135
+
136
+ // Compiles CoffeeScript to JavaScript
118
137
coffee : {
119
138
options : {
120
139
sourceMap : true ,
@@ -139,6 +158,8 @@ module.exports = function (grunt) {
139
158
} ]
140
159
}
141
160
} , < % if ( compassBootstrap ) { % >
161
+
162
+ // Compiles Sass to CSS and generates necessary files if requested
142
163
compass : {
143
164
options : {
144
165
sassDir : '<%%= yeoman.app %>/styles' ,
@@ -160,11 +181,8 @@ module.exports = function (grunt) {
160
181
}
161
182
}
162
183
} , < % } % >
163
- // not used since Uglify task does concat,
164
- // but still available if needed
165
- // concat: {
166
- // dist: {}
167
- // },
184
+
185
+ // Renames files for browser caching purposes
168
186
rev: {
169
187
dist : {
170
188
files : {
@@ -177,19 +195,27 @@ module.exports = function (grunt) {
177
195
}
178
196
}
179
197
} ,
198
+
199
+ // Reads HTML for usemin blocks to enable smart builds that automatically
200
+ // concat, minify and revision files. Creates configurations in memory so
201
+ // additional tasks can operate on them
180
202
useminPrepare: {
181
203
html : '<%%= yeoman.app %>/index.html' ,
182
204
options : {
183
205
dest : '<%%= yeoman.dist %>'
184
206
}
185
207
} ,
208
+
209
+ // Performs rewrites based on rev and the useminPrepage configuration
186
210
usemin: {
187
211
html : [ '<%%= yeoman.dist %>/{,*/}*.html' ] ,
188
212
css : [ '<%%= yeoman.dist %>/styles/{,*/}*.css' ] ,
189
213
options : {
190
214
assetsDirs : [ '<%%= yeoman.dist %>' ]
191
215
}
192
216
} ,
217
+
218
+ // The following *-min tasks produce minified files in the dist folder
193
219
imagemin: {
194
220
dist : {
195
221
files : [ {
@@ -210,31 +236,10 @@ module.exports = function (grunt) {
210
236
} ]
211
237
}
212
238
} ,
213
- // By default, your `index.html` <!-- Usemin Block --> will take care of
214
- // minification. This option is pre-configured if you do not wish to use
215
- // Usemin blocks.
216
- // cssmin: {
217
- // dist: {
218
- // files: {
219
- // '<%%= yeoman.dist %>/styles/main.css': [
220
- // '.tmp/styles/{,*/}*.css',
221
- // '<%%= yeoman.app %>/styles/{,*/}*.css'
222
- // ]
223
- // }
224
- // }
225
- // },
226
- // uglify: {
227
- // dist: {
228
- // files: {
229
- // '<%%= yeoman.dist %>/scripts/scripts.js': [
230
- // '<%%= yeoman.dist %>/scripts/scripts.js'
231
- // ]
232
- // }
233
- // }
234
- // },
235
239
htmlmin: {
236
240
dist : {
237
241
options : {
242
+ // Optional configurations that you can uncomment to use
238
243
// removeCommentsFromCDATA: true,
239
244
// collapseBooleanAttributes: true,
240
245
// removeAttributeQuotes: true,
@@ -251,7 +256,28 @@ module.exports = function (grunt) {
251
256
} ]
252
257
}
253
258
} ,
254
- // Put files not handled in other tasks here
259
+
260
+ // Allow the use of non-minsafe AngularJS files. Automatically makes it
261
+ // minsafe compatible so Uglify does not destroy the ng references
262
+ ngmin: {
263
+ dist : {
264
+ files : [ {
265
+ expand : true ,
266
+ cwd : '.tmp/concat/scripts' ,
267
+ src : '*.js' ,
268
+ dest : '.tmp/concat/scripts'
269
+ } ]
270
+ }
271
+ } ,
272
+
273
+ // Replace Google CDN references
274
+ cdnify: {
275
+ dist : {
276
+ html : [ '<%%= yeoman.dist %>/*.html' ]
277
+ }
278
+ } ,
279
+
280
+ // Copies remaining files to places other tasks can use
255
281
copy: {
256
282
dist : {
257
283
files : [ {
@@ -282,6 +308,8 @@ module.exports = function (grunt) {
282
308
src : '{,*/}*.css'
283
309
}
284
310
} ,
311
+
312
+ // Run some tasks in parallel to speed up the build process
285
313
concurrent: {
286
314
server : [
287
315
'coffee:dist' , < % if ( compassBootstrap ) { % >
@@ -302,29 +330,43 @@ module.exports = function (grunt) {
302
330
'htmlmin'
303
331
]
304
332
} ,
333
+
334
+ // By default, your `index.html`'s <!-- Usemin block --> will take care of
335
+ // minification. These next options are pre-configured if you do not wish
336
+ // to use the Usemin blocks.
337
+ // cssmin: {
338
+ // dist: {
339
+ // files: {
340
+ // '<%%= yeoman.dist %>/styles/main.css': [
341
+ // '.tmp/styles/{,*/}*.css',
342
+ // '<%%= yeoman.app %>/styles/{,*/}*.css'
343
+ // ]
344
+ // }
345
+ // }
346
+ // },
347
+ // uglify: {
348
+ // dist: {
349
+ // files: {
350
+ // '<%%= yeoman.dist %>/scripts/scripts.js': [
351
+ // '<%%= yeoman.dist %>/scripts/scripts.js'
352
+ // ]
353
+ // }
354
+ // }
355
+ // },
356
+ // concat: {
357
+ // dist: {}
358
+ // },
359
+
360
+ // Test settings
305
361
karma : {
306
362
unit : {
307
363
configFile : 'karma.conf.js' ,
308
364
singleRun : true
309
365
}
310
- } ,
311
- cdnify: {
312
- dist : {
313
- html : [ '<%%= yeoman.dist %>/*.html' ]
314
- }
315
- } ,
316
- ngmin: {
317
- dist : {
318
- files : [ {
319
- expand : true ,
320
- cwd : '.tmp/concat/scripts' ,
321
- src : '*.js' ,
322
- dest : '.tmp/concat/scripts'
323
- } ]
324
- }
325
366
}
326
367
} ) ;
327
368
369
+
328
370
grunt . registerTask ( 'serve ', function ( target ) {
329
371
if ( target === 'dist' ) {
330
372
return grunt . task . run ( [ 'build' , 'connect:dist:keepalive' ] ) ;
0 commit comments