-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
201 lines (167 loc) · 5.53 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/**
* Dependencies
**********************************************************/
var gulp = require('gulp'),
webp = require('gulp-webp'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
changed = require('gulp-changed'),
tinypng = require('gulp-tinypng'),
imagemin = require('gulp-imagemin'),
rubySass = require('gulp-ruby-sass'),
minifycss = require('gulp-minify-css'),
browserSync = require('browser-sync'),
autoprefixer = require('gulp-autoprefixer');
/**
* File Paths (relative to assets folder)
**********************************************************/
var paths = {
sassSrc : ['assets/scss/**/*.scss', '!assets/scss/**/_*.scss'],
cssDest : 'assets/css',
jsHintSrc : [
'assets/js/main.js'
],
jsMinifySrc : [ // non-concatenated
'assets/js/vendor/modernizr.js'
],
jsConcatSrc : [
'assets/js/main.js'
],
jsDest : 'assets/js/build',
pngSrc : ['assets/img/**/*.png', '!assets/img/build/**/*'],
jpgSrc : ['assets/img/**/*.jpg', 'assets/img/**/*.jpeg', '!assets/img/build/**/*'],
gifSrc : ['assets/img/**/*.gif', '!assets/img/build/**/*'],
imgSrc : ['assets/img/**/*.jpg', 'assets/img/**/*.jpeg', 'assets/img/**/*.gif', '!assets/img/build/**/*'],
imgDest : 'assets/img/build',
webpDest: 'assets/img/build/webp'
};
/**
* Config
**********************************************************/
/**
* custom-config.js is used to store configuration settings
* that shouldn't be kept in sync with everyone else. This
* file is ignored by git.
*/
var customConfig = require('./custom-config'),
tinypngApiKey = customConfig.tinypngApiKey,
serverHost = customConfig.serverHost,
serverPort = customConfig.serverPort;
var config = {
serverHost : serverHost,
serverPort : serverPort,
webpEnable : false,
tinypng : tinypngApiKey // https://tinypng.com/developers
};
/**
* Browser Sync
**********************************************************/
gulp.task('browser-sync', function() {
// If server host is not set run a static-server
if (config.serverHost == '') {
browserSync.init(['_site/assets/css/*.css', '_site/**/*.html'], {
server: {
baseDir: '_site'
}
});
} else {
browserSync.init(['_site/assets/css/*.css', '_site/**/*.html'], {
proxy: {
host: config.serverHost
}
});
}
});
/**
* Sass Tasks
**********************************************************/
gulp.task('sass', function() {
gulp.src(paths.sassSrc)
.pipe(rubySass({ style: 'expanded', compass: true }))
.pipe(autoprefixer(
'last 2 version',
'> 1%',
'ie 8',
'ie 9',
'ios 6',
'android 4'
))
.pipe(gulp.dest(paths.cssDest))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest(paths.cssDest));
});
/**
* JavaScript Tasks
**********************************************************/
// JSHint custom js
gulp.task('js-hint', function() {
gulp.src(paths.jsHintSrc)
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter(stylish));
});
// Minify all js files that should not be concatenated
gulp.task('js-uglify', function() {
gulp.src(paths.jsMinifySrc)
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(paths.jsDest));
});
// Minify and concatenate all other js
gulp.task('js-concat', function() {
gulp.src(paths.jsConcatSrc)
.pipe(uglify())
.pipe(concat('scripts.min.js'))
.pipe(gulp.dest(paths.jsDest));
});
/**
* Compress Images
**********************************************************/
gulp.task('images', function() {
// ImageMin for jpg and gifs
gulp.src(paths.imgSrc)
.pipe(changed(paths.imgDest))
.pipe(imagemin({ optimizationLevel: 7, progressive: true, interlaced: true }))
.pipe(gulp.dest(paths.imgDest));
// Use TinyPNG if API Key is entered otherwise use ImageMin
if (config.tinypng != '') {
gulp.src(paths.pngSrc)
.pipe(changed(paths.imgDest))
.pipe(tinypng(config.tinypng))
.pipe(gulp.dest(paths.imgDest));
} else {
gulp.src(paths.pngSrc)
.pipe(changed(paths.imgDest))
.pipe(imagemin({ optimizationLevel: 7 }))
.pipe(gulp.dest(paths.imgDest));
}
// Create WebP images if enabled
if (config.webpEnable != false) {
gulp.src(paths.jpgSrc)
.pipe(changed(paths.imgDest))
.pipe(webp())
.pipe(gulp.dest(paths.webpDest));
}
});
/**
* Gulp Tasks
**********************************************************/
// Jekyll
gulp.task('jekyll', function() {
require('child_process').spawn('jekyll', ['build'], {stdio: 'inherit'});
});
// Watch for file changes
gulp.task('watch', function() {
gulp.watch([paths.sassSrc, 'assets/scss/**/_*.scss'], ['sass']);
gulp.watch(paths.jsHintSrc, ['js-hint']);
gulp.watch(paths.jsMinifySrc, ['js-uglify']);
gulp.watch(paths.jsConcatSrc, ['js-concat']);
gulp.watch(paths.jpgSrc, ['images']);
gulp.watch(paths.pngSrc, ['images']);
gulp.watch(['assets/css/*.css', '**/*.html', '!_site/**/*.html', '**/*.markdown'], ['jekyll']);
});
// Default task
gulp.task('default', ['sass', 'js-hint', 'js-uglify', 'js-concat', 'images', 'jekyll', 'browser-sync', 'watch']);