-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
132 lines (114 loc) · 3.47 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync');
var useref = require('gulp-useref');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var cssnano = require('gulp-cssnano');
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var del = require('del');
var runSequence = require('run-sequence');
var cp = require('child_process');
var autoprefixer = require('gulp-autoprefixer');
var jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'bundle exec jekyll build';
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
const dest = 'public';//'_site/dist';
/**
* Build the Jekyll Site
*/
gulp.task('jekyll-build', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.exec( jekyll , (done)=>{
return done;
})
// .on('close', done);
});
/**
* Rebuild Jekyll & do page reload
*/
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
//compiling sass files
gulp.task('sass', function(){
return gulp.src('app/scss/**/*.scss')
.pipe(sass())
.pipe(autoprefixer())
.pipe(gulp.dest('app/css'))
.pipe(browserSync.reload({
stream:true
}));
});
//optimize images
gulp.task('images', function(){
return gulp.src(['_site/app/img/**/*.+(png|jpg|gif|svg)', '!app/img/originalImages/', '!app/img/originalImages/**/*'])
.pipe(cache(imagemin({
//Setting interlced to true
progressive:true,
interlced:true,
})))
.pipe(gulp.dest(dest+'/img/'));
});
//copying font files
gulp.task('fonts', function(){
return gulp.src('_site/app/fonts/**/*')
.pipe(gulp.dest(dest+'/fonts'));
});
//copying video files
gulp.task('video', function(){
return gulp.src('_site/app/res/**/*')
.pipe(gulp.dest(dest+'/res'));
});
//cleaning up
//cleant the directory
gulp.task('clean:dist', function(){
return del.sync(dest+'');
});
//clear the image cache
gulp.task('clean:cache', function(callback){
return cache.clearAll(callback);
});
//initializing the development environment
gulp.task('browserSync',function(){
browserSync.init({
server:{baseDir:'_site/app'}
});
});
//initializing the production environment
gulp.task('productionServer', function(){
browserSync.init({
server:{baseDir:dest+''}
});
});
//copying minified files with html files
gulp.task('useref', function(){
return gulp.src('_site/app/*.html')
.pipe(useref())
//minifies only if it's a js file
.pipe(gulpIf('*.js', uglify()))
//minifies only if it's a css file
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest(dest+''));
});
//development workflow : watch tasks
gulp.task('watch', ['sass','jekyll-build','browserSync'],function(){
gulp.watch(['app/scss/**/*.scss','app/css/**/*.css'],['sass', 'jekyll-rebuild']);
gulp.watch(['app/**/*.html','_layouts/**', '_includes/**','_projects/**','_experiences/**'],['jekyll-rebuild']);
gulp.watch('app/js/**/*.js', ['jekyll-rebuild']);
gulp.watch('app/**/*.md', ['jekyll-rebuild']);
gulp.watch('_config.yml', ['jekyll-rebuild']);
});
gulp.task('default', ['watch']);
//producation workflow
gulp.task('build',function(callback){
runSequence('clean:dist',
'sass',
'jekyll-build',
['useref','images','fonts', 'video'],
'productionServer',
callback
);
});