-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
344 lines (323 loc) · 14.6 KB
/
gulpfile.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
// Load plugins
var gulp = require('gulp'),
gutil = require('gulp-util'),
watch = require('gulp-watch'),
prefix = require('gulp-autoprefixer'),
minifyCSS = require('gulp-minify-css'),
sass = require('gulp-sass'),
imagemin = require('gulp-imagemin'),
svgmin = require('gulp-svgmin'),
size = require('gulp-size'),
rename = require('gulp-rename'),
pngcrush = require('imagemin-pngcrush'),
browserSync = require('browser-sync'),
csslint = require('gulp-csslint'),
browserReload = browserSync.reload,
rimraf = require('gulp-rimraf'),
cp = require('child_process');
// Initialize browser-sync which starts a static server also allows for
// browsers to reload on filesave
gulp.task('browser-sync', function() {
browserSync.init(null, {
server: {
baseDir: "./_site"
}
});
});
// Function to call for reloading browsers
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('minify-css', function(){
gulp.src('./css/a.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('a.min.css'))
.pipe(gulp.dest('./css/'));
gulp.src('./css/b.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('b.min.css'))
.pipe(gulp.dest('./css/'));
gulp.src('./css/black.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('black.min.css'))
.pipe(gulp.dest('./css/'));
gulp.src('./css/blue.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('blue.min.css'))
.pipe(gulp.dest('./css/'));
gulp.src('./css/green.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('green.min.css'))
.pipe(gulp.dest('./css/'));
gulp.src('./css/lime.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('lime.min.css'))
.pipe(gulp.dest('./css/'));
gulp.src('./css/orange.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('orange.min.css'))
.pipe(gulp.dest('./css/'));
gulp.src('./css/pink.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('pink.min.css'))
.pipe(gulp.dest('./css/'));
gulp.src('./css/purple.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('purple.min.css'))
.pipe(gulp.dest('./css/'));
gulp.src('./css/red.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('red.min.css'))
.pipe(gulp.dest('./css/'));
gulp.src('./css/sun.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('sun.min.css'))
.pipe(gulp.dest('./css/'));
gulp.src('./css/teal.css') // set this to the file(s) you want to minify.
.pipe(minifyCSS())
.pipe(size({gzip: false, showFiles: true, title:'minified css'}))
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('teal.min.css'))
.pipe(gulp.dest('./css/'));
});
// Task to optimize and minify svg
gulp.task('minify-svg', function(){
gulp.src('./img/svg')
.pipe(svgmin())
.pipe(gulp.dest('./img/svg'));
});
gulp.task('minify-images', function(){
gulp.src('./img/*')
.pipe(size({gzip: false, showFiles: true, title:'original image size'}))
.pipe(size({gzip: true, showFiles: true, title:'original image size'}))
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngcrush()]
}))
.pipe(size({gzip: false, showFiles: true, title:'minified images'}))
.pipe(size({gzip: true, showFiles: true, title:'minified images'}))
.pipe(gulp.dest('./img')); // change the dest if you don't want your images overwritten
});
// Use csslint without box-sizing or compatible vendor prefixes (these
// don't seem to be kept up to date on what to yell about)
gulp.task('csslint', function(){
gulp.src('./css/*.css')
.pipe(csslint({
'compatible-vendor-prefixes': false,
'box-sizing': false,
'important': false
}))
.pipe(csslint.reporter());
});
// Task that compiles scss files down to good old css
// TODO: switch to an array of css files
gulp.task('pre-process', function(){
gulp.src('./_sass/a.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
gulp.src('./_sass/b.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
gulp.src('./_sass/black.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
gulp.src('./_sass/blue.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
gulp.src('./_sass/green.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
gulp.src('./_sass/lime.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
gulp.src('./_sass/orange.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
gulp.src('./_sass/pink.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
gulp.src('./_sass/purple.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
gulp.src('./_sass/red.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
gulp.src('./_sass/sun.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
gulp.src('./_sass/teal.scss')
.pipe(watch(function(files) {
return files.pipe(sass()).on('error', errorHandler)
.pipe(size({gzip: false, showFiles: true, title:'without vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'without vendor prefixes'}))
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'after vendor prefixes'}))
.pipe(size({gzip: true, showFiles: true, title:'after vendor prefixes'}))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream:true}));
}));
});
gulp.task('production', function(){
gulp.run('minify-css', 'minify-img', 'minify-svg');
});
// Remove _site from directory before committing
gulp.task('clean', function() {
return gulp.src('_site/', { read: false })
.pipe(rimraf({ force: true }));
});
// Build the Jekyll Site
gulp.task('jekyll-build', function (done) {
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
});
// Watch & Build the Jekyll Site
gulp.task('jekyll-watch', function (done) {
return cp.spawn('jekyll', ['build', '--watch', '--force_polling'], {stdio: 'inherit'})
.on('close', done);
});
// Serve the Jekyll Site
gulp.task('jekyll-serve', function (done) {
return cp.spawn('jekyll', ['serve', '--watch', '--config', '_config.yml,_development_config.yml'], {stdio: 'inherit'})
.on('close', done);
});
// gulp.task('jekyll', function(done) {
// return cp.spawn('bundle', ['exec', 'jekyll', 'build', '-q'])
// })
/*
DEFAULT TASK
• Process sass then auto-prefixes and lints outputted css
• Starts a server on port 3000
• Reloads browsers when you change html or sass files
*/
gulp.task('default', ['pre-process', 'minify-css'], function(){
gulp.start('pre-process', 'csslint');
gulp.watch(['_includes/*', '_layouts/*', '_posts/*', '_resources/*', '_sass/*', '*.html', '_*config.yml'], ['jekyll-build']);
gulp.watch('_sass/*.scss', ['pre-process', 'minify-css']);
gulp.watch('css/a.css', ['minify-css']);
});
/* ORIGINAL
gulp.task('default', ['pre-process', 'minify-css', 'bs-reload', 'browser-sync'], function(){
gulp.start('pre-process', 'csslint');
gulp.watch(['_includes/*', '_layouts/*', '_posts/*', '_resources/*', '_sass/*', '*.html', '_*config.yml'], ['jekyll-build']);
gulp.watch('sass/*.scss', ['pre-process', 'minify-css']);
gulp.watch('css/a.css', ['bs-reload', 'minify-css']);
gulp.watch('*.html', ['bs-reload'])
});
*/
// Handle errors
// http://stackoverflow.com/questions/24011349/gulp-error-events-js72
function errorHandler (error) {
console.log(error.toString());
this.emit('end');
}