forked from chadev/chadev.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
69 lines (61 loc) · 2.23 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
// include gulp and required plugins
var gulp = require('gulp');
var sass = require('gulp-ruby-sass');
var browserSync = require('browser-sync');
var notify = require('gulp-notify');
var imagemin = require('gulp-imagemin');
var pngcrush = require('imagemin-pngcrush');
var cp = require('child_process');
var os = require('os');
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
// build the jekyll site
gulp.task('jekyll-build', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn(batchify('jekyll'), ['build'], {stdio: 'inherit'})
.on('close', done);
});
// rebuild jekyll and do page reload
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
// compile sass into both _site/assets/css (for live injecting) and site (for future jekyll builds)
gulp.task('compile-sass', function () {
return gulp.src('assets/sass/**/*.scss')
.pipe(sass({ style: 'compressed'}))
.on("error", notify.onError(function (error) {
return "Dang! " + error.message;
}))
.pipe(gulp.dest('assets/css'))
.pipe(gulp.dest('_site/assets/css'));
});
// minify PNG, JPEG, GIF and SVG images
gulp.task('imagemin', function () {
return gulp.src('assets/images/**/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngcrush()]
}))
.pipe(gulp.dest('_site/assets/images/'));
});
// start a server and watch for html and css changes
gulp.task('browser-sync', ['compile-sass', 'jekyll-build'], function() {
browserSync.init(['_site/assets/css/*.css'], {
server: {
baseDir: '_site'
}
});
});
// watch for changes
gulp.task('default', ['imagemin', 'browser-sync'], function () {
gulp.watch(['assets/sass/**/*.scss'], ['compile-sass']);
gulp.watch(['assets/images/**/*'], ['imagemin']);
gulp.watch([ '*.yml', '*.md', '_devs/*.md', '*.html', '_includes/*.html', '_layouts/*.html'], ['jekyll-rebuild']);
});
// Windows environments may need to run batch versions of scripts.
function batchify(filename) {
var isWin = /^win/.test(os.platform());
return isWin ? filename + '.bat' : filename;
}