-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
115 lines (104 loc) · 3.19 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
var gulp = require('gulp'),
watch = require('gulp-watch'),
sass = require('gulp-sass'),
neat = require('node-neat').includePaths,
cp = require('child_process'),
rename = require('gulp-rename'),
cssmin = require('gulp-cssmin'),
concat = require('gulp-concat'),
browserSync = require('browser-sync'),
autoprefixer = require('gulp-autoprefixer'),
uglify = require('gulp-uglify'),
del = require('del'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
critical = require('critical'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
reload = browserSync.reload();
var paths = {
scss: '_src/scss/**/*',
html: '**/*.html',
js: '_src/js/**/*',
images: '_src/img/**/*',
posts: '_posts/**/*.html',
dest: 'dist/'
};
gulp.task('sass', function () {
gulp.src('_src/scss/*.scss')
.pipe(plumber())
.pipe(sass({
includePaths: ['sass'].concat(neat) // required for node-neat to work
}))
.on('error', function (err) { // custom error logging since Gulp crashes without it
console.log(err);
})
.pipe(autoprefixer('last 2 version', 'ie 9')) // prefix up to ie9
.pipe(cssmin()) // minify the css while we're at it
.pipe(gulp.dest('./dist/css')) // specify the destination for the minified css created by sass
.pipe(gulp.dest('./_site/dist/css')) // also output to the _site directory for live injecting
.pipe(browserSync.reload({stream:true}))
.pipe(notify({ message: 'Compiled Sass!' }));
});
gulp.task('js', function() {
gulp.src('_src/js/**/*.js')
.pipe(concat('scripts.js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('./dist/js'))
.pipe(notify({ message: 'Minified JS.'}));
});
gulp.task('clean', function() {
return del([
'dist/css','dist/js', 'dist/img'
]);
});
gulp.task('critical-css', function() {
critical.generate({
base: '_site',
src: 'index.html',
dest: './dist/css/critical.min.css',
width: 1200,
height: 900,
minify: true
});
});
gulp.task('images', function() {
return gulp.src(paths.images)
.pipe(imagemin({
progressive: true,
svgoPlugins: [
{ removeViewBox: false },
{ cleanupIDs: false }
],
use: [pngquant()]
}))
.pipe(gulp.dest('_site/dist/img'))
.pipe(gulp.dest('dist/img'));
});
gulp.task('jekyll-build', function(done) {
browserSync.notify('<span style="color: grey">Running:</span> $ jekyll build');
return cp.spawn('jekyll', ['build'], { stdio: 'inherit' })
.on('close', done);
});
gulp.task('jekyll-rebuild', ['jekyll-build'], function() {
browserSync.reload();
});
gulp.task('browsersync', ['jekyll-build'], function() {
browserSync({
server: {
baseDir: './_site/'
},
host: 'localhost'
});
});
gulp.task('watch', function() {
gulp.watch(paths.scss, ['sass']);
gulp.watch(paths.js, ['js']);
gulp.watch(paths.html, ['jekyll-rebuild']);
gulp.watch(paths.posts, ['jekyll-rebuild']);
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['clean'], function() {
gulp.start('sass', 'js', 'images', 'browsersync', 'watch');
});