-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·180 lines (165 loc) · 4.58 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
// Gulp and node
const gulp = require('gulp');
const cp = require('child_process');
// Basic workflow plugins
const browserSync = require('browser-sync');
const sass = require('gulp-sass');
const jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
const messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
// Performance workflow plugins
const htmlmin = require('gulp-htmlmin');
const prefix = require('gulp-autoprefixer');
const sourcemaps = require('gulp-sourcemaps');
const concat = require('gulp-concat');
//const uglify = require('gulp-uglify');
const uglify = require('gulp-uglify-es').default;
const critical = require('critical');
// Image Generation TODO
const responsive = require('gulp-responsive');
const $ = require('gulp-load-plugins')();
const rename = require('gulp-rename');
const imagemin = require('gulp-imagemin');
const src = {
css: '_sass/main.scss',
js: '_js/**/*.js',
}
const dist = {
css: '_site/assets/css',
js: '_site/assets/js',
}
// Build the Jekyll Site
gulp.task('jekyll-build', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn( jekyll , ['build'], {stdio: 'inherit'})
.on('close', done);
});
gulp.task('deploy', ['jekyll-build'], function () {
return gulp.src('./_site/**/*')
.pipe(deploy());
});
// Rebuild Jekyll & do page reload
gulp.task('rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
// Rebuild Jekyll & do page reload
gulp.task('browser-sync', ['sass', 'js', 'jekyll-build'], function() {
browserSync({
server: {
baseDir: '_site'
}
});
});
// Complie SCSS to CSS & Prefix
gulp.task('sass', function() {
return gulp.src(src.css)
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'compressed',
includePaths: ['scss'],
// functions: sassFunctions(),
onError: browserSync.notify
}))
.pipe(prefix())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest(dist.css))
.pipe(browserSync.reload({ stream: true }))
.pipe(gulp.dest('assets/css'));
});
// Uglify JS
gulp.task('js', function() {
return gulp.src([
'node_modules/jquery/dist/jquery.slim.min.js',
'node_modules/popper.js/dist/popper.min.js',
'node_modules/bootstrap/dist/js/bootstrap.min.js',
'node_modules/lazysizes/plugins/unveilhooks/ls.unveilhooks.js',
'node_modules/lazysizes/lazysizes.js',
'node_modules/velocity-animate/velocity.js',
src.js
])
.pipe(concat('bundle.js'))
.pipe(uglify())
.pipe(gulp.dest(dist.js))
.pipe(browserSync.reload({stream: true}))
.pipe(gulp.dest('assets/js'))
.on('error', function(err){
console.error('Error in uglify taks', err.toString());
});
});
gulp.task('critical', function (cb) {
critical.generate({
base: '_site/',
src: 'index.html',
css: ['assets/css/main.css'],
dimensions: [{
width: 320,
height: 480
},{
width: 768,
height: 1024
},{
width: 1280,
height: 960
}],
dest: '../_includes/critical.css',
minify: true,
extract: false,
ignore: ['@font-face']
});
});
gulp.task('watch', function() {
gulp.watch('_sass/**/*.scss', ['sass']);
gulp.watch(['*.html', '_layouts/*.html', '_includes/*.html', '_posts/*.md', 'pages_/*.md', '_include/*html'], ['rebuild']);
gulp.watch('_js/**/*.js', ['js']);
});
gulp.task('default', ['browser-sync', 'watch']);
// Minify HTML
gulp.task('html', function() {
gulp.src('./_site/index.html')
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('./_site'))
gulp.src('./_site/*/*html')
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('./_site/./'))
});
// Images
gulp.task('img', function() {
return gulp.src('_img/posts/*.{png,jpg}')
.pipe($.responsive({
// For all the images in the folder
'*': [{
width: 230,
rename: {suffix: '_placehold'},
}, {
// thubmnail
width: 535,
rename: { suffix: '_thumb' },
}, {
// thumbnail @2x
width: 535 * 2,
rename: { suffix: '_thumb@2x' },
}, {
width: 575,
rename: { suffix: '_xs'}
}, {
width: 767,
rename: {suffix: '_sm'}
}, {
width: 991,
rename: { suffix: '_md' }
}, {
width: 1999,
rename: { suffix: '_lg' }
}, {
// max-width hero
width: 1920,
}],
}, {
quality: 70,
progressive: true,
withMetadata: false,
}))
.pipe(imagemin())
.pipe(gulp.dest('assets/img/posts/'));
});