-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
executable file
·111 lines (98 loc) · 2.28 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const sass = require('gulp-sass');
const autoprefixer = require('autoprefixer');
const cp = require('child_process');
const postcss = require('gulp-postcss');
const cssnano = require('cssnano');
const del = require('del');
const env = process.env.NODE_ENV || 'prod';
const jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
const messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build',
};
var paths = {
styles: {
src: '_scss/*.scss',
dest: '_site/assets/css',
destsecond: 'assets/css',
},
scripts: {
src: 'assets/js/*.js',
dest: '_site/assets/js',
},
};
/**
* Build the Jekyll Site
*/
function jekyllBuild() {
browserSync.notify(messages.jekyllBuild);
if (env === 'prod') {
return cp.spawn(jekyll, ['build'], { stdio: 'inherit' });
} else {
return cp.spawn(
jekyll,
['build', '--config', '_config.yml,_config.dev.yml'],
{
stdio: 'inherit',
},
);
}
}
function style() {
const processors = [
autoprefixer(),
cssnano,
];
return gulp
.src('_scss/main.scss')
.pipe(
sass({
includePaths: ['scss'],
onError: browserSync.notify,
}),
)
.pipe(postcss(processors))
.pipe(gulp.dest(paths.styles.dest))
.pipe(browserSync.reload({ stream: true }))
.pipe(gulp.dest(paths.styles.destsecond));
}
function reload(done) {
browserSync.reload();
done();
}
function browserSyncServe() {
browserSync.init({
server: {
baseDir: '_site',
},
notify: false
});
}
function watch() {
gulp.watch(paths.styles.src, style);
gulp.watch(
[
'*.html',
'_layouts/*.html',
'_pages/*',
'_pages/*/*',
'_includes/*',
'assets/scripts/*.js',
'assets/img/*.*',
// './**/*.md' // causes infinite loop
],
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));