-
Notifications
You must be signed in to change notification settings - Fork 1
/
gruntfile.js
263 lines (223 loc) · 7.27 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
// gruntfile.js
module.exports = function(grunt) {
require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// HTML Hint Block
htmlhint: {
build: {
options: {
'tag-pair': true, // always watch for matching end-tags
'tagname-lowercase': true, // lowercase for tagnames
'attr-lowercase': true, // lowercase for attributes
'attr-value-double-quotes': true, // double quotationmarks for attributes
'doctype-first': true, // Check for a doctype
'spec-char-escape': true, // Check for unescaped special characters
'id-unique': true, // Check for unique IDs, not unique -> kickbandie
'head-script-disabled': true, // Scripts go to the footer
/*
We are not looking for style in our head as we
need that for the critical CSS part. Also it might make sense
to have scripts in your head… whyever… then remove the last line
from the htmlhint-block.
*/
},
src: ['unminified-html/index-unminified.html'] // check all HTML files in this directory
}
},
// HTML Minification Block
htmlmin: {
// mumin stands for "MarkUp MINification"
htmlmin: {
options: {
collapseWhitespace: true, // yes, we want exactly that
preserveLineBreaks: true, // safety first, can be removed later
removeComments: true, // this is already optional but I like it that way
keepClosingSlash: true // this is something I always do and want to keep
},
files: {
'index.html': 'unminified-html/index-unminified.html' // minify HTML files in this directory and place them in the root
}
}
},
// LESS to CSS Block
less: {
atf: { // above the fold CSS
options: {
paths: ['less/atf/'], // watch this folder
report: true // report in the terminal what you did
},
files: {
'less/projectname-atf.css' : 'less/atf/combined-projectname-atf.less' // create the "above-the-fold" Stylesheet
}
},
main: { // Main CSS-File
options: {
paths: ['less/main/'], // watch this folder
report: true // report in the terminal what you did
},
files: {
'less/projectname-main.css' : 'less/main/combined-projectname-main.less' // create the main Stylesheet
}
},
print: {
options: {
paths: ['less/print/'], // watch this folder
report: true // tell me what happened
},
files: {
'less/projectname-print.css' : 'less/print/combined-projectname-print.less' // create a Print Stylesheet
}
}
},
// PostCSS Block
postcss: {
options: {
map: {
inline: false, // saving sourcemaps as separate files
annotation: 'css/maps/' // putting sourcemaps here
},
processors: [
require('autoprefixer')({browsers: 'last 2 versions'}), // autoprefixer plugin with setting
require('cssnano')() // cssnano = minifier for CSS
]
},
dist: {
src: 'less/*.css',
dest: 'css/*.min.css'
}
},
// Javascript Concatenation Block
concat: {
options: {
separator: ';' // separate all our scripts with semicolons
},
dist: {
src: ['uncompressed-js/*.js'], // take all scripts from this folder
dest: 'concatenated/projectname.concat.js' // concatenate them into one and put it here
}
},
// Javascript Uglification Block
uglify: {
// yeah, we don't support IE8 here in JS lands
options: {
screwIE8: true
},
// first of all I want to have a readable concatenated file
beauty: {
options: {
// so we beautify
beautify: {
width: 75,
beautify: true
},
// and we don't mangle
mangle: false
},
files: {
'concatenated/beauty/projectname.beauty.js': 'concatenated/projectname.concat.js'
}
},
// uglyfying the concatenated JS file
ugly: {
// standard, no options, just compression and mangling the whole thing
files: {
'js/projectname.concat.min.js': 'concatenated/projectname.concat.js'
}
},
// special task in order to minify each script on its own without concatenation
// TO DO: currently throws an error after it has run, that the task cannot be found
ugly2production: {
// in this case it's only whitespace-trimming here
options: {
mangle: false,
compress: false
},
files: [{
expand: true,
cwd: 'uncompressed-js',
src: '*.js',
dest: 'js/'
}]
}
},
// Image Compression Block
imagemin: {
png: {
options: {
optimizationLevel: 2 // compression level
},
files: [{
expand: true, // Dynamic expansion of capabilities
cwd: 'raw', // cwd = current working directory = where do we have the uncompressed images
src: ['**/*.png'], // check for all png files in cwd
dest: 'images', // put images into this directory after compression
ext: '.png' // give them the extension .png
}]
},
jpg: {
options: {
progressive: true // progressive conversion, compress that JPG
},
files: [{
expand: true, // see for png
cwd: 'raw',
src: ['**/*.jpg'],
dest: 'images',
ext: '.jpg'
}]
}
},
// Watch Block
watch: {
options: {
livereload: true,
},
htmlhint: {
files: ['unminified-html/*.html'], // watch all html-files for changes
tasks: ['htmlhint'] // when changes -> do lint
},
htmlmin: {
files: ['unminified-html/*.html'], // watch all html-files for changes
tasks: ['htmlmin'] // when changes -> do minify
},
atf: {
files: ['less/atf/*.less'], // watch all .less files for the above-the-fold CSS for changes
tasks: ['lessy-atf'] // when changes -> do all defined tasks (see grunt.registerTask 'lessy-atf')
},
main: {
files: ['less/main/*.less'], // watch all .less files for the main CSS for changes
tasks: ['lessy-main'] // when changes -> do all defined tasks (see grunt.registerTask 'lessy-main')
},
print: {
files: ['less/print/*.less'], // watch all .less files for the print CSS for changes
tasks: ['lessy-print'] // when changes -> do all defined tasks (see grunt.registerTask 'lessy-print')
},
beauty: {
files: ['uncompressed-js/*.js'], // watch all separated and unminified js files for changes
tasks: ['jayessy-beauty'] // when changes -> do all defined tasks
},
ugly: {
files: ['uncompressed-js/*.js'], // watch all separated and unminified js files for changes
tasks: ['jayessy-ugly'] // when changes -> do all defined tasks
},
ugly2production: {
files: ['uncompressed-js/*.js'],
tasks: ['ugly2production']
},
imagemin: {
files: ['raw/*.jpg', 'raw/*.png'], // watch for images with those extensions being put into the raw folder
tasks: ['imageminify'] // new images -> do task
}
}
});
grunt.registerTask('default', []);
grunt.registerTask('html-processing', ['htmlhint', 'htmlmin']);
grunt.registerTask('lessy-atf', ['less:atf', 'postcss']);
grunt.registerTask('lessy-main', ['less:main', 'postcss']);
grunt.registerTask('lessy-print', ['less:print', 'postcss']);
grunt.registerTask('jayessy-beauty', ['concat', 'uglify:beauty']);
grunt.registerTask('jayessy-ugly', ['concat', 'uglify:ugly']);
grunt.registerTask('ugly2production', ['uglify:ugly2production']);
grunt.registerTask('imageminify', ['imagemin']); // giving both the same name causes issues
}