-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
136 lines (122 loc) · 4.02 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
133
134
135
136
var gulp = require('gulp');
var browserSync = require('browser-sync');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var cache = require('gulp-cache');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var fs = require('fs');
var merge = require('merge-stream');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var cp = require('child_process');
var cssnano = require('gulp-cssnano');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var watch = require('gulp-watch');
sass.compiler = require('sass');
var jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
var messages = {
jekyllServe: '<span style="color: grey">Running:</span> $ jekyll serve'
};
/**
* Build the Jekyll Site
*/
gulp.task('jekyllServe', ['img', 'fonts', 'sass', 'js'], function (done) {
browserSync.notify(messages.jekyllServe);
return cp.spawn('bundle', ['exec', jekyll, 'serve'], { stdio: 'inherit' })
.on('close', done);
});
/**
* Wait for jekyll-build, then launch the Server
*/
gulp.task('browserSync', ['jekyllServe'], function () {
browserSync({
server: {
baseDir: '_site'
}
});
});
// Compress images
gulp.task('img', function() {
return gulp.src('images/**/*')
.pipe(cache(imagemin({
interlaced: true,
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
})))
.pipe(gulp.dest('images'))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('fonts', function () {
return gulp.src([
'./node_modules/font-awesome/fonts/*',
]).pipe(gulp.dest('assets/dist/fonts/'));
});
/**
* Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
*/
gulp.task('sass', function () {
var sassStream,
cssStream;
//compile sass
sassStream = gulp.src('src/scss/style.scss')
.pipe(sass({
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(prefix(['last 3 versions'], { cascade: true }));
//select additional css files
cssStream = gulp.src([
'./node_modules/font-awesome/css/font-awesome.css',
'./node_modules/bootstrap/dist/css/bootstrap.css',
'./node_modules/beerslider/dist/BeerSlider.unmin.css',
]);
//merge the two streams and concatenate their contents into a single file
return merge(cssStream, sassStream)
.pipe(sourcemaps.init())
.pipe(concat('style.css'))
.pipe(cssnano())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/dist/css'))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task('js', function () {
return gulp.src([
'./node_modules/jquery/dist/jquery.js',
'./node_modules/liquidjs/dist/liquid.min.js',
'./node_modules/lunr/lunr.js',
'./node_modules/bootstrap/dist/js/bootstrap.js',
'./node_modules/html5shiv/dist/html5shiv.js',
'./node_modules/jquery.instagramfeed/jquery.instagramFeed.js',
'./node_modules/beerslider/dist/BeerSlider.unmin.js',
].concat(['src/js/*']))
.pipe(sourcemaps.init())
.pipe(concat('main.js'))
.pipe(uglify({ mangle: false }))
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest('assets/dist/js'))
.pipe(browserSync.reload({ stream: true }));
});
function pausableWatch(watchedFiles, tasks) {
var watcher = watch(watchedFiles, function() {
watcher.close();
gulp.start(tasks, function() {
pausableWatch(watchedFiles, tasks);
});
});
}
/**
* Watch img/scss/js files for changes & recompile
*/
gulp.task('watch', function () {
pausableWatch(['images/**/*'], ['img']);
pausableWatch(['src/scss/*.scss', 'src/scss/*/*.scss'], ['sass']);
pausableWatch(['src/js/*.js'], ['js']);
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', ['watch', 'browserSync']);