-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
85 lines (79 loc) · 2.18 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
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const sass = require('gulp-sass');
const prefix = require('autoprefixer');
// const cp = require('child_process');
const postcss = require('gulp-postcss');
const cssnano = require('cssnano');
const spawn = require('cross-spawn');
const env = process.env.NODE_ENV || 'prod';
const processors = [prefix(),cssnano];
const messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build',
};
var paths = {
styles: {
src: 'assets/scss/*.scss',
dest: '_site/assets/css',
destsecond: 'assets/css',
},
scripts: {
src: 'assets/js/*.js',
dest: '_site/assets/js',
destsecond: 'assets/js',
},
};
/**
* Build the Jekyll Site
*/
function jekyllBuild() {
browserSync.notify(messages.jekyllBuild);
if (env === 'prod') {
return spawn('jekyll', ['build', '--config', '_config.yml'], { stdio: 'inherit' });
} else {
return spawn('jekyll', ['build', '--config', '_config.yml,_config.dev.yml'], { stdio: 'inherit' });
}
}
function style() {
return gulp
.src(paths.styles.src)
.pipe(sass({includePaths: ['scss', 'css', 'node_modules'],onError: browserSync.notify}))
.pipe(postcss(processors))
.pipe(gulp.dest(paths.styles.dest))
.pipe(gulp.dest(paths.styles.destsecond))
.pipe(browserSync.reload({ stream: true }));
}
// Reload files
function reload(done) {
browserSync.reload();
done();
}
// Dest files
function browserSyncServe() {
browserSync.init({
server: {
baseDir: '_site',
},
});
}
// Gulp watch files
function watch() {
gulp.watch(paths.styles.src, style);
gulp.watch(['*.html','_layouts/*','_includes/*','html/**/*','assets/**/*'],gulp.series(jekyllBuild, reload));
}
/**
* Rebuild Jekyll & do page reload
*/
gulp.task('jekyll-rebuild', gulp.series(jekyllBuild, reload));
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
* To run locally:
* $ NODE_ENV=dev gulp
*/
gulp.task('default', gulp.parallel(jekyllBuild, browserSyncServe, watch));
/**
* Production task
* $ NODE_ENV=dev prod
*/
gulp.task('deploy', gulp.parallel(reload, jekyllBuild));