Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
executable file
·103 lines (86 loc) · 2.84 KB
/
Copy pathgulpfile.js
File metadata and controls
executable file
·103 lines (86 loc) · 2.84 KB
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
// =====================================
// Required
// =====================================
var gulp = require('gulp'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
uglify = require('gulp-uglify'),
sass = require('gulp-sass'),
plumber = require('gulp-plumber'),
autoprefixer = require('gulp-autoprefixer'),
rename = require('gulp-rename'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
cp = require('child_process');
// =====================================
// Jekyll Task
// =====================================
// Build the Jekyll Site
gulp.task('jekyll-build', function (done) {
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
});
// Rebuild Jekyll & do page reload
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
// =====================================
// Browser-Sync Task
// =====================================
gulp.task('browser-sync', ['sass', 'jekyll-build'], function() {
browserSync({
server:{
baseDir: "_site"
}
});
});
// =====================================
// Sass Tasks
// =====================================
gulp.task('sass', function() {
gulp.src('assets/css/main.scss')
.pipe(plumber())
.pipe(sass({outputStyle: 'compressed'}))
.pipe(autoprefixer('last 2 versions'))
.pipe(gulp.dest('_site/assets/css'))
.pipe(reload({stream:true}))
.pipe(gulp.dest('assets/css'));
});
// =====================================
// Scripts
// =====================================
gulp.task('scripts', function() {
gulp.src(['assets/js/**/*.js', '!assets/js/**/*.min.js'])
.pipe(plumber())
.pipe(rename({suffix:'.min'}))
.pipe(uglify())
.pipe(gulp.dest('_site/assets/js'))
.pipe(reload({stream:true}))
.pipe(gulp.dest('assets/js'));
});
// =====================================
// Imagemin Task
// =====================================
gulp.task('images', function () {
gulp.src('assets/img/**/*.+(png|jpg|jpeg|gif|svg)')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('_site/assets/img'))
.pipe(reload({stream:true}));
});
// =====================================
// Watch Tasks
// =====================================
gulp.task('watch', function() {
gulp.watch('assets/css/**', ['sass']);
gulp.watch('assets/js/**', ['scripts']);
gulp.watch('assets/img/**', ['images']);
gulp.watch(['index.html', '_includes/*' , '_layouts/*.html', '_posts/*'], ['jekyll-rebuild']);
});
// =====================================
// Default Task
// =====================================
gulp.task('default', ['sass', 'images', 'scripts','browser-sync', 'watch']);