-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
97 lines (87 loc) · 2.29 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
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var cp = require('child_process');
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
/**
* Build the Jekyll Site
*/
gulp.task('jekyll-build', function(done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn('bundle', 'exec jekyll build --config _config.yml,_config_dev.yml'.split(' '), {
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', ['sass', 'jekyll-build'], function() {
browserSync.init({
server: {
baseDir: '_site',
},
open: false
});
});
/**
* Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
*/
gulp.task('sass', function() {
return gulp.src('assets/scss/main.scss')
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: ['assets/scss'],
outputStyle: "compact",
onError: browserSync.notify
}))
.on('error', onError)
.pipe(prefix(['last 3 versions', '> 1%'], {
cascade: true
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/css'))
.pipe(gulp.dest('_site/assets/css'))
.pipe(browserSync.reload({
stream: true
}))
});
/**
* Watch scss files for changes & recompile
* Watch html/md files, run jekyll & reload BrowserSync
*/
gulp.task('watch', ['watch-sass', 'watch-jekyll']);
gulp.task('watch-sass', function() {
gulp.watch('assets/scss/**/*.scss', ['sass']);
});
gulp.task('watch-jekyll', function() {
gulp.watch([
'**/*',
'!assets/css/**/*',
'!assets/scss/**/*',
'!node_modules/**/*',
'!_site/**/*',
'!facebook-sync/**/*',
'!*',
'*.html',
'*.yml',
], ['jekyll-rebuild']);
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', ['browser-sync', 'watch']);
function onError(err) {
console.error(err.stack);
this.emit('end');
}