-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
102 lines (91 loc) · 2.54 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
var gulp = require('gulp');
var csso = require('gulp-csso');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var path = require('path');
var folders = require('gulp-folders');
var sass = require('gulp-sass');
var plumber = require('gulp-plumber');
var cp = require('child_process');
var imagemin = require('gulp-imagemin');
var browserSync = require('browser-sync');
var jekyllCommand = (/^win/.test(process.platform)) ? 'jekyll.bat' : 'jekyll';
/*
* Build the Jekyll Site
* runs a child process in node that runs the jekyll commands
*/
gulp.task('jekyll-build', function (done) {
return cp.spawn(jekyllCommand, ['build'], {stdio: 'inherit'})
.on('close', done);
});
/*
* Rebuild Jekyll & reload browserSync
*/
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
/*
* Build the jekyll site and launch browser-sync
*/
gulp.task('browser-sync', ['jekyll-build'], function() {
browserSync({
server: {
baseDir: '_site'
},
port: 2000,
open: false,
ghostMode: false
});
});
/*
* Compile and minify sass
*/
gulp.task('sass', function() {
gulp.src('src/styles/**/*.scss')
.pipe(plumber())
.pipe(sass())
.pipe(csso())
.pipe(gulp.dest('assets/css/'));
});
/*
* Compile fonts
*/
gulp.task('fonts', function() {
gulp.src('src/fonts/**/*.{ttf,woff,woff2}')
.pipe(plumber())
.pipe(gulp.dest('assets/fonts/'));
});
/*
* Minify images
*/
gulp.task('imagemin', function() {
return gulp.src('src/img/**/*.{jpg,png,gif}')
.pipe(plumber())
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
.pipe(gulp.dest('assets/img/'));
});
/**
* Compile and minify js
*/
// gulp.task('js', function(){
// return gulp.src('src/js/**/*.js')
// .pipe(plumber())
// .pipe(concat('main.js'))
// .pipe(uglify())
// .pipe(gulp.dest('assets/js/'))
// });
gulp.task('js', folders('src/js', function(folder){
return gulp.src(path.join('src/js', folder, '**/*.js'))
.pipe(plumber())
.pipe(concat(folder + '.js'))
.pipe(uglify())
.pipe(gulp.dest('assets/js/'));
}));
gulp.task('watch', function() {
gulp.watch(['*.{html,md}', '{3ddl,neuro,_content,_includes,_layouts}/**/*.{md,html}', '_data/**/*.yml'], ['jekyll-rebuild']);
gulp.watch('src/**/*.s{a,c}ss', ['sass', 'jekyll-rebuild']);
gulp.watch('src/js/**/*.js', ['js', 'jekyll-rebuild']);
gulp.watch('src/fonts/**/*.{tff,woff,woff2}', ['fonts']);
gulp.watch('src/img/**/*.{jpg,png,gif}', ['imagemin']);
});
gulp.task('default', ['js', 'sass', 'fonts', 'imagemin', 'browser-sync', 'watch']);