-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
137 lines (123 loc) Β· 4.12 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
137
var gulp = require('gulp');
var gnotify = require('gulp-notify');
var browserSync = require('browser-sync');
var del = require('del');
var concat = require('gulp-concat');
var gulpif = require('gulp-if');
var sass = require('gulp-sass');
var scsslint = require('gulp-scss-lint');
var cleanCSS = require('gulp-clean-css');
var minifyJs = require('gulp-uglify');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var imageMin = require('gulp-imagemin');
var runSequence = require('run-sequence');
var cp = require('child_process');
var path = require('path');
var prod = false;
var jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
// Keep source directory in sync with _config.yml
var PATHS = {
source: path.join(__dirname, 'source'),
public: path.join(__dirname, 'public')
};
gulp.task('clean', function(done) {
return del(path.join(PATHS.public, '**/*'));
});
gulp.task('jekyll-build', function(done) {
cp.spawn(jekyll, ['build', !prod ? '--drafts' : null], { stdio: 'inherit' })
.on('close', function(code) {
done(code === 0 ? null : 'ERROR: Jekyll process exited with code: ' + code);
});
});
gulp.task('jekyll-rebuild', ['jekyll-build'], function() {
browserSync.reload();
});
gulp.task('browser-sync', ['build'], function() {
browserSync({
notify: false,
open: false,
server: {
baseDir: 'public'
}
});
});
gulp.task('js', function() {
return gulp.src([
// Add your JS dependencies here to include them in the bundle.
'node_modules/fastclick/lib/fastclick.js',
path.join(PATHS.source, 'js/vendor/*.js'),
path.join(PATHS.source, 'js/helpers.js'),
path.join(PATHS.source, 'js/main.js'),
path.join(PATHS.source, 'js/components/*.js')
])
.pipe(gulpif(!prod, sourcemaps.init()))
.pipe(concat('main.js'))
.pipe(gulpif(!prod, sourcemaps.write()))
.pipe(gulpif(prod, minifyJs()))
.pipe(gulp.dest(path.join(PATHS.public, 'js')))
.pipe(gulpif(!prod, browserSync.reload({ stream: true })));
});
gulp.task('images', function() {
return gulp.src(path.join(PATHS.source, 'images/**/*'))
.pipe(gulpif(prod, imageMin({
progressive: true,
interlaced: true,
multipass: true
})))
.pipe(gulp.dest(path.join(PATHS.public, 'images')))
.pipe(gulpif(!prod, browserSync.reload({ stream: true })));
});
gulp.task('fonts', function() {
return gulp.src([
path.join(PATHS.source, 'fonts/**/*')
])
.pipe(gulp.dest(path.join(PATHS.public, 'fonts')))
.pipe(gulpif(!prod, browserSync.reload({ stream: true })));
});
gulp.task('sass', function() {
return gulp.src(path.join(PATHS.source, 'sass/**/*.scss'))
.pipe(gulpif(!prod, sourcemaps.init()))
.pipe(scsslint({
'config': '.scss-lint.yml'
}))
.pipe(sass({
outputStyle: 'expanded',
includePATHS: [
'scss'
]
})
.on('error', sass.logError))
.on('error', gnotify.onError({
title: 'Sass Error',
message: 'Error in file <%= error.message %>'
}))
.pipe(autoprefixer({
browsers: ['> 5%', 'IE >= 9']
}))
.pipe(gulpif(!prod, sourcemaps.write()))
.pipe(gulpif(prod, cleanCSS({
// CSS animations on IE/Edge seem to need units on zero.
compatibility: '-properties.zeroUnits'
})))
.pipe(gulp.dest(path.join(PATHS.public, 'css')))
.pipe(gulpif(!prod, browserSync.reload({ stream: true })));
});
gulp.task('watch', function() {
gulp.watch(path.join(PATHS.source, 'images/**/*'), ['images']);
gulp.watch(path.join(PATHS.source, 'sass/**/*.scss'), ['sass']);
gulp.watch(path.join(PATHS.source, 'js/**/*.js'), ['js']);
gulp.watch([
path.join(PATHS.source, '**/*.html'),
path.join(PATHS.source, '**/*.yml'),
path.join('!', PATHS.public, '**/*')
], ['jekyll-rebuild']);
});
gulp.task('build', function(done) {
runSequence('fonts', ['js', 'images', 'sass', 'jekyll-build'], done);
});
gulp.task('default', ['browser-sync', 'watch']);
gulp.task('prod', function(done) {
prod = true;
runSequence('clean', ['build'], done);
});