-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
86 lines (74 loc) · 2.46 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
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'
};
gulp.task('jekyll-dev', function (done) {
browserSync.notify(messages.jekyllDev);
return cp.spawn('jekyll', ['build', '--drafts', '--config', '_config.yml,_config_dev.yml'], {stdio: 'inherit'})
.on('close', done);
});
gulp.task('jekyll-rebuild', ['jekyll-dev'], function () {
browserSync.reload();
});
gulp.task('browser-sync', ['sass', 'scripts', 'jekyll-dev'], function() {
browserSync.init({
server: "_site",
port: 4001
});
});
gulp.task('sass', function () {
return gulp.src('_sass/main.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'));
});
gulp.task('scripts', function() {
return gulp.src(['_js/*.js'])
.pipe(concat('scripts.js'))
.pipe(gulp.dest('_site/js'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('js'));
});
gulp.task('watch', function () {
gulp.watch(['_sass/**/*.scss','_sass/*.scss'], ['sass']);
gulp.watch(['_js/**/*.js', '_js/*.js'], ['scripts']);
gulp.watch(['index.html', '_layouts/*.html', '_posts/*', '_includes/*.html', '_drafts/*', '**/*.html'], ['jekyll-rebuild']);
});
gulp.task('jekyll-prod', function (done) {
browserSync.notify(messages.jekyllProd);
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
});
gulp.task('sass-prod', 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(cssnano())
.pipe(gulp.dest('_site/css'))
.pipe(gulp.dest('css'));
});
gulp.task('scripts-prod', function() {
return gulp.src(['_js/*.js'])
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(gulp.dest('_site/js'))
.pipe(gulp.dest('js'));
});
gulp.task('default', ['browser-sync', 'watch']);
gulp.task('build', ['scripts-prod', 'sass-prod', 'jekyll-prod']);