-
Notifications
You must be signed in to change notification settings - Fork 0
/
browsersync.js
52 lines (45 loc) · 1.29 KB
/
browsersync.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
const browserSync = require('browser-sync').create();
const cp = require('child_process');
const jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
const scssPath = '_scss/**/*.scss';
const jsPath = '_scripts/*.js';
const templatePath = [
'*.html',
'+(_includes|_layouts)/*.html',
'*.yml',
'_data/*.yml',
'_posts/*',
];
module.exports = gulp => {
const reloadBrowser = done => {
browserSync.reload();
done();
};
// run `jekyll build`
gulp.task('jekyll-build', done => {
return cp.spawn(jekyll, ['build'], { stdio: 'inherit' }).on('close', done);
});
// run `jekyll build` with _config_dev.yml
gulp.task('jekyll-dev', done => {
return cp
.spawn(jekyll, ['build', '--config', '_config.yml,_config_dev.yml'], {
stdio: 'inherit',
})
.on('close', done);
});
// Rebuild Jekyll then reload the page
gulp.task('jekyll-rebuild', gulp.series(['jekyll-dev', reloadBrowser]));
gulp.task(
'serve',
gulp.series('jekyll-dev', () => {
browserSync.init({
server: {
baseDir: '_site',
},
});
gulp.watch(scssPath, gulp.series(['sass', reloadBrowser]));
gulp.watch(jsPath, gulp.series(['scripts', reloadBrowser]));
gulp.watch(templatePath, gulp.task('jekyll-rebuild'));
})
);
};