This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
98 lines (87 loc) · 2.38 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
var gulp = require('gulp');
var shell = require('gulp-shell');
var minifyHTML = require('gulp-minify-html');
var runSequence = require('run-sequence');
var autoprefixer = require('gulp-autoprefixer');
var uncss = require('gulp-uncss');
var minifyCss = require('gulp-minify-css');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var jpegtran = require('imagemin-jpegtran');
var gifsicle = require('imagemin-gifsicle');
var replace = require('gulp-replace');
var fs = require('fs');
gulp.task('jekyll-build', function () {
return gulp.src('index.html', { read: false })
.pipe(shell([
'bundle exec jekyll build --config _config.yml'
]));
});
gulp.task('jekyll-build-staging', function () {
return gulp.src('index.html', { read: false })
.pipe(shell([
'bundle exec jekyll build --config _config.yml,_config-staging.yml'
]));
});
gulp.task('optimize-images', function () {
return gulp.src(['_site/**/*.jpg', '_site/**/*.jpeg', '_site/**/*.gif', '_site/**/*.png'])
.pipe(imagemin({
progressive: false,
svgoPlugins: [{ removeViewBox: false }],
use: [pngquant(), jpegtran(), gifsicle()]
}))
.pipe(gulp.dest('_site/'));
});
gulp.task('optimize-css', function () {
return gulp.src('_site/assets/css/main.css')
.pipe(autoprefixer())
// Deactiated because it was not working together with AddThis and Cookie-Bar
// .pipe(uncss({
// html: ['_site/**/*.html'],
// ignore: []
// }))
.pipe(minifyCss({ keepBreaks: false }))
.pipe(gulp.dest('_site/assets/css/'));
});
gulp.task('optimize-html', function () {
return gulp.src('_site/**/*.html')
.pipe(minifyHTML({
quotes: true
}))
.pipe(replace('<link rel="stylesheet" href="/assets/css/main.css">', function (s) {
var style = fs.readFileSync('_site/assets/css/main.css', 'utf8');
return '<style>\n' + style + '\n</style>';
}))
.pipe(gulp.dest('_site/'));
});
gulp.task('build', function (callback) {
runSequence(
'jekyll-build',
'optimize-images',
'optimize-css',
'optimize-html',
callback
);
});
gulp.task('build-staging', function (callback) {
runSequence(
'jekyll-build-staging',
'optimize-images',
'optimize-css',
'optimize-html',
callback
);
});
gulp.task('assets', function (callback) {
runSequence(
'optimize-images',
'optimize-css',
callback
);
});
gulp.task('css', function (callback) {
runSequence(
'optimize-css',
callback
);
});