-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
94 lines (80 loc) · 3.26 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
// Source: https://www.chenhuijing.com/blog/gulp-jekyll-github/
var gulp = require('gulp');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var cssnano = require('gulp-cssnano');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var cp = require('child_process');
var messages = {
jekyllDev: 'Running: $ jekyll build for dev',
jekyllProd: 'Running: $ jekyll build for prod'
};
// Build the Jekyll Site in development mode
gulp.task('jekyll-dev', function (done) {
browserSync.notify(messages.jekyllDev);
return cp.spawn('bundle', [ 'exec', 'jekyll', 'build', '--drafts', '--config', '_config.yml,_config_dev.yml'], {stdio: 'inherit'})
.on('close', done);
});
// Rebuild Jekyll & reload the page
gulp.task('jekyll-rebuild', ['jekyll-dev'], function () {
browserSync.reload();
});
// Wait for jekyll-dev task to complete, then launch the Server
gulp.task('browser-sync', ['sass', 'scripts', 'jekyll-dev'], function() {
browserSync.init({
server: "_site",
port: 3000
});
});
// Compile files from _scss folder into _site/css folder (for live injecting)
gulp.task('sass', function () {
return gulp.src('_sass/styles.scss')
.pipe(sass({
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(gulp.dest('_site/css'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('css'));
});
// Compile files from _js/lib folder into both _site/js folder (for live injecting) and site folder (for future Jekyll builds)
gulp.task('scripts', function() {
return gulp.src(['_js/lib/*.js'])
.pipe(concat('scripts.js'))
.pipe(gulp.dest('_site/js'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('js'));
});
// Watch scss files for changes & recompile. Watch html/md files, run jekyll & reload BrowserSync
gulp.task('watch', function () {
gulp.watch(['_sass/**/*.scss','_sass/*.scss'], ['sass']);
gulp.watch(['_js/**/*.js'], ['scripts'])
gulp.watch(['index.*', '_layouts/*.html', '_posts', '_includes/*.html', '_drafts/*', '**/*.md', '**/*.html', '_data/*.yml'], ['jekyll-rebuild']);
});
// Build the Jekyll Site in production mode
gulp.task('jekyll-prod', function (done) {
browserSync.notify(messages.jekyllProd);
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
});
// Build the Jekyll Site in production mode
gulp.task('jekyll-prod', function (done) {
browserSync.notify(messages.jekyllProd);
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
});
// Identical Javascript compilation task to development mode, with an additional minification step thrown in using uglify
gulp.task('scripts-prod', function() {
return gulp.src(['_js/lib/*.js'])
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(gulp.dest('_site/js'))
.pipe(gulp.dest('js'));;
});
// Build task, run using gulp build to compile Sass and Javascript ready for deployment.
gulp.task('build', ['scripts-prod', 'sass-prod', 'jekyll-prod']);
// Default task, running just gulp will compile the sass, compile the Jekyll site, launch BrowserSync & watch files.
gulp.task('default', ['browser-sync', 'watch']);