-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
390 lines (354 loc) · 9.85 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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/*global module */
/*global require */
(function () {
'use strict';
module.exports = function (grunt) {
// Apparently I have to require mozjpeg anyways
// need to research why. Is it because it's not
// seen as a grunt package?
var mozjpeg = require('imagemin-mozjpeg');
// require time-grunt at the top and pass in the grunt instance
// it will measure how long things take for performance
//testing
require('time-grunt')(grunt);
// load-grunt will read the package file and automatically
// load all our packages configured there.
// Yay for laziness
require('load-grunt-tasks')(grunt);
grunt.initConfig({
// Reference to the package file
pkg: grunt.file.readJSON('package.json'),
// JAVASCRIPT TASKS
// Hint the grunt file and all files under js/
// and one directory below
jshint: {
files: [ 'Gruntfile.js', 'js/{,*/}*.js'],
options: {
reporter: require('jshint-stylish')
// options here to override JSHint defaults
}
},
// Takes all the files under js/ and concatenates
// them together. I've chosen not to mangle the compressed file
uglify: {
main: {
options: {
mangle: false,
sourceMap: true,
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> ' +
'Released under the MIT license http://caraya.mit-license.org/*/'
},
files: {
'js/build.js': [ 'js/*.js' ],
}
},
libs: {
options: {
mangle: false,
sourceMap: true
},
files: {
'lib/vendor/allLibs.js': [
'lib/vendor/*.js',
'!lib/vendor/modernizr-2.8.3.min.js' ],
}
},
plugins: {
options: {
mangle:false,
sourceMap: true
},
files: {
'lib/plugins/allPlugs.js': [ 'lib/plugins/*.js' ]
}
}
},
// OPTIONAL JS TASKS
// Both Coffescript and Babel will generate Javascript files.
// May want to run them before concat and uglify to make sure we
// have all our files ready to be processed.
// If you're using either Babel or Coffeescript run the corresponding
// task below
// COFFEESCRIPT
// If you want to use coffeescript (http://coffeescript.org/)
// change the cwd value to the locations of your coffee files
coffee: {
files: {
expand: true,
flatten: true,
cwd: 'coffee',
src: ['*.coffee'],
dest: 'js/',
ext: '.js'
}
},
// BABEL
// Babel allows you to transpile ES6 to current ES5 without needing
// a plugin or anything installed in your application. This will
// eventually go away when I'm happy with ES6 support in browsers
// See http://babeljs.io/ for more information.
babel: {
options: {
sourceMap: true
},
dist: {
files: {
'es6/*.js': 'src/*.js'
}
}
},
// SASS AND CSS RELATED TASKS
// Converts all the files under scss/ ending with .scss
// into the equivalent css file on the css/ directory
sass: {
dev: {
options: {
style: 'expanded'
},
files: [ {
expand: true,
cwd: 'sass',
src: [ '*.scss'],
dest: 'css',
ext: '.css'
}]
},
production: {
options: {
style: 'compress'
},
files: [ {
expand: true,
cwd: 'sass',
src: [ '*.scss'],
dest: 'css',
ext: '.css'
}]
}
},
// This task requires the scss-lint ruby gem to be
// installed on your system If you choose not to
// install it, comment out this task and the prep-css
// and work-lint tasks below
//
// I've chosen not to fail on errors or warnings.
scsslint: {
allFiles: [
'scss/*.scss',
'scss/modules/_mixins.scss',
'scss/modules/_variables.scss',
'scss/partials/*.scss'],
options: {
force: true,
colorizeOutput: true
}
},
// Optional CSS Post Process
// Autoprefixer will check caniuse.com's database and
// add the necessary prefixes to CSS elements as needed.
// This saves us from doing the work manually
autoprefixer: {
options: {
browsers: [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
]
},
files: {
expand: true,
flatten: true,
src: 'css/*.css',
dest: 'css/*.css'
}
},
// UNCSS will analyzes the your HTML pages and
// remove from the CSS all the classes that are
// not used in any of your HTML pages
//
// This task needs to be run in the processed CSS
// rather than the SCSS files
//
//See https://github.com/addyosmani/grunt-uncss
// for more information
uncss: {
dist: {
files: {
'dist/css/main.css': [ 'dist/*.html' ]
}
}
},
imagemin: {
png: {
options: {
optimizationLevel: 7
},
files: [
{
// Set to true to enable the following options…
expand: true,
// cwd is 'current working directory'
cwd: 'images/',
src: ['**/*.png'],
// Could also match cwd line above. i.e. project-directory/img/
dest: 'dist/images/',
ext: '.png'
}
]
},
jpg: {
options: {
progressive: true,
use: [mozjpeg()]
},
files: [
{
// Set to true to enable the following options…
expand: true,
// cwd is 'current working directory'
cwd: 'images/',
src: ['**/*.jpg'],
// Could also match cwd. i.e. project-directory/img/
dest: 'dist/images/',
ext: '.jpg'
}
]
}
},
// GH-PAGES TASK
// Push the specified content into the repositories
// gh-pages branch
'gh-pages': {
options: {
message: 'Content committed from Grunt gh-pages',
dotfiles: true,
base: 'dist/'
},
// These files will get pushed to the `
// gh-pages` branch (the default)
src: ['**/*']
},
// FILE MANAGEMENT
// Can't seem to make the copy task create the directory
// if it doesn't exist so we go to another task to create
// the fn directory
mkdir: {
build: {
options: {
create: [ 'dist' ]
}
}
},
// Copy the files from our repository into the dist
// directory. Do not do deep copy of HTML files.
// It'll copy stuff that we keep around for testing,
// like the webfont loader docs. Either delete the
// webfont loader stuff or just copy html from the
// top level directory (which I changed it to do)
copy: {
dist: {
files: [ {
expand: true,
src: [
'fonts/**/*',
'css/**/*',
'lib/**/*',
'js/**/*',
'*.html'],
dest: 'dist/'
}]
}
},
// Clean the build directory
clean: {
all: [ 'dist/' ]
},
perfbudget: {
all: {
options: {
url: 'https://caraya.github.io/books-as-apps/typography.html',
key: 'A.be974c9b235f69677db80813612925c6',
budget: {
visualComplete: '4000',
SpeedIndex: '1500'
}
}
}
},
critical: {
typography: {
options: {
minify: true,
base: './',
css: [
'css/main.css'
],
width: 1200,
height: 800
},
src: 'typography.html',
dest: 'dist/typography.html'
}
},
// Compare the size of the listed files
compare_size: {
files: [
'dist/js/*.js',
'dist/css/*.css'
],
options: {
// Location of stored size data
cache: '.sizecache.json',
// Compressor label-function pairs
compress: {
gz: function (fileContents) {
return require('gzip-js').zip(fileContents, {}).length;
}
}
}
}
});
// closes initConfig
// CUSTOM TASKS
// Usually a combination of one or more tasks defined above
grunt.task.registerTask(
'lint',
[ 'jshint' ]
);
grunt.task.registerTask(
'publish',
[ 'clean:all', 'copy:dist', 'imagemin', 'gh-pages' ]
);
grunt.task.registerTask(
'lint-all',
[ 'scsslint', 'jshint']
);
// Prep CSS starting with SASS, autoprefix et. al
grunt.task.registerTask(
'prep-css',
[ 'scsslint', 'sass:dev', 'autoprefixer' ]
);
grunt.task.registerTask(
'optional-js',
[ 'coffeescript', 'babel' ]
);
grunt.task.registerTask(
'prep-js',
[ 'jshint', 'concat:dist', 'uglify' ]
);
grunt.task.registerTask(
'all-js',
[' optional-js', 'prep-js' ]
);
};
// closes module.exports
}
());
// closes the use strict function