-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
110 lines (92 loc) · 2.67 KB
/
gulpfile.babel.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
"use strict";
import gulp from 'gulp';
import browserSync from 'browser-sync';
import cleanCSS from 'gulp-clean-css';
import htmltidy from 'gulp-htmltidy';
import rmEmptyLines from 'gulp-remove-empty-lines';
import uglify from 'gulp-uglify';
import child_process from 'child_process';
const exec = child_process.exec;
const paths = {
build: '_site',
css: 'css',
scripts: ['js']
};
const cssFiles = [
'css/**/*',
]
const jsFiles = [
'js/**/*.js'
]
const jekyllFiles = [
'*.{html,yml,markdown,md}',
'_posts/*.{markdown,md}',
'_layouts/**/*.html',
'_includes/**/*.html'
];
const messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
const errorHandler = error => {
console.error(String(error));
this.emit('end');
browserSync.notify('Error');
}
gulp.task('jekyll-build', done => {
exec('bundle exec jekyll build', (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
done(err);
});
});
gulp.task('js', () => {
return gulp.src(jsFiles)
.pipe(gulp.dest(paths.build + '/' + paths.scripts))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('css-build', gulp.series('jekyll-build', () => {
return gulp.src(paths.css + '/*.css')
// .pipe(sass({
// includePaths: ['node_modules']
// }).on('error', errorHandler))
.pipe(gulp.dest(paths.build + '/' + paths.css))
}));
gulp.task('htmltidy', gulp.series('jekyll-build', () => {
return gulp.src([paths.build + '/**/*.html'])
.pipe(htmltidy({doctype: 'html5',
hideComments: true,
indent: true}))
.pipe(rmEmptyLines())
.pipe(gulp.dest(paths.build));
}));
gulp.task('minify', () => {
return gulp.src([paths.build + '/' + paths.css + '/*.css'])
.pipe(
cleanCSS({
debug: true,
keepBreaks: true,
keepSpecialComments: false
}, function(details) {
console.log(details.name + ': ' + details.stats.originalSize + ' ==> ' + details.stats.minifiedSize);
}))
.pipe(gulp.dest(paths.build + '/' + paths.css))
});
gulp.task('serve', gulp.series(gulp.parallel('js', 'css-build'), done => {
browserSync.init({
server: {
baseDir: paths.build,
},
notify: false
});
gulp.watch(jekyllFiles).on('all', gulp.series('css-build'));
gulp.watch(cssFiles).on('change', gulp.series('css-build'));
gulp.watch(jsFiles).on('change', gulp.series('js'));
gulp.watch(paths.build).on('all', browserSync.reload);
return console.log('Initializing Server...'), done();
}));
gulp.task('travis', gulp.series(gulp.parallel('css-build', 'js', 'htmltidy', 'minify'), done => {
console.log('complete'), done();
}));
gulp.task('default', gulp.series('serve'));