-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
88 lines (77 loc) · 2.44 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
//참고: https://gist.github.com/dope/071dc7741f6ab2c77116#file-gulpfile-js
var gulp = require('gulp');
var browserSync = require('browser-sync');
var less = require('gulp-less');
var autoprefixer = require('gulp-autoprefixer');
var minifyCSS = require('gulp-minify-css');
var notify = require('gulp-notify');
var gutil = require('gulp-util');
var cp = require('child_process');
var path = require('path');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
var reload = browserSync.reload;
/**
* Build the Jekyll Site
*/
gulp.task('jekyll-build', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
});
/**
* Rebuild Jekyll & do page reload
*/
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
/**
* Wait for jekyll-build, then launch the Server
*/
gulp.task('browser-sync', ['less', 'jekyll-build'], function() {
browserSync({
notify: true,
logPrefix: "[Browser Sync]",
server: {
baseDir: '_site'
}
});
});
// minifiy js
gulp.task('compress', function() {
gulp.src('js/*.js')
.pipe(uglify())
.pipe(gulp.dest('js/min'))
});
// minifiy images
gulp.task('images', function () {
return gulp.src('images/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('images'));
});
gulp.task('less', function () {
gulp.src('static/less/style.less')
.pipe(less({
paths: [ path.join(__dirname, 'less', 'includes') ]
}))
.pipe(less({compress: true}).on('error', gutil.log))
.pipe(less().on('error', gutil.log))
.pipe(autoprefixer('last 10 versions', 'ie 9'))
.pipe(minifyCSS({keepBreaks: false}))
.pipe(gulp.dest('static/css'))
.pipe(gulp.dest('_site/static/css'))
.pipe(notify('Less Compiled, Prefixed and Minified'));
});
gulp.task('watch', function () {
gulp.watch('static/less/*.less', ['less', reload]);
gulp.watch(['index.html', '_layouts/*.html', '_posts/*.md', 'static/js/**/*', 'static/img/*'], ['jekyll-rebuild']);
});
gulp.task('default', ['browser-sync', 'watch']);