-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
326 lines (247 loc) · 6.39 KB
/
gulpfile.babel.js
File metadata and controls
326 lines (247 loc) · 6.39 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
'use strict';
// ---
// Setup: load plugins and define config variables
// ---
// Plugins
import gulp from 'gulp';
import cp from 'child_process';
import shell from 'gulp-shell';
import sequence from 'run-sequence';
import rename from 'gulp-rename';
import svgSymbols from 'gulp-svg-symbols';
import cheerio from 'gulp-cheerio';
import svgmin from 'gulp-svgmin';
import browserSync from 'browser-sync';
import sass from 'gulp-sass';
import cleanCSS from 'gulp-clean-css';
import postcss from 'gulp-postcss';
import autoprefixer from 'autoprefixer';
import sourcemaps from 'gulp-sourcemaps';
import babel from 'gulp-babel';
import concat from 'gulp-concat';
import uglify from 'gulp-uglify';
import critical from 'critical';
import gnf from 'gulp-npm-files';
import del from 'del';
// Config
const config = {
browsersync: {
server: {
baseDir: '_site',
reloadDelay: 2000,
debounce: 200,
notify: true,
ghostMode: {
clicks: true,
location: true,
forms: true,
scroll: false
}
}
},
buildmessage: '<span style="color: rgba(#fff,.3)">Building</span> jekyll',
symbols: {
title: '%f symbol',
svgClassname: 'c-symbol-set',
templates: ['default-svg']
},
cheerio: {
run: function ($) {
$('[fill]').removeAttr('fill');
},
parserOptions: { xmlMode: true }
},
sass: {
outputStyle: 'compressed'
},
autoprefixer: {
browsers: [
'last 2 version',
'> 2%',
'ie >= 9',
'ios >= 8',
'android >= 4'
]
},
cleancss: {
mediaMerging: false,
keepSpecialComments: 0
},
jsConcat: 'theme.js',
minifyjsConcat: 'theme.min.js',
};
const paths = {
vendor: 'vendor/',
scssSrc: '_scss/**/*.scss',
cssSrc: 'css/',
cssDist: '_site/css/',
jsSrc: [
'vendor/svgxuse/svgxuse.min.js',
'vendor/jquery/dist/jquery.min.js',
'vendor/gsap/src/uncompressed/TweenMax.js',
'vendor/scrollmagic/scrollmagic/uncompressed/ScrollMagic.js',
'vendor/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js',
'vendor/scrollmagic/scrollmagic/uncompressed/plugins/debug.addIndicators.js',
'vendor/jquery-smooth-scroll/jquery.smooth-scroll.min.js',
'vendor/jquery-match-height/jquery.matchHeight.js',
'js/_components/*.js'
],
jsDist: 'js/',
jsJekyllDist: '_site/js/',
symbolsSrc: '_artwork/symbols/*.svg',
symbolsDist: 'img/svg/',
cssWatch: '_scss/**/*.scss',
jsWatch: 'js/_components/**/*.js',
symbolsWatch: '_artwork/symbols/*.svg',
siteWatch: [
'img/**/*.png',
'img/**/*.jpg',
'img/**/*.svg',
'**/*.markdown',
'**/*.html',
'_posts/*.md',
'_data/*.yaml',
'_config.yml',
'!_site/**/*.*'
]
}
// ---
// Install
// ---
// Copy dependencies from `node_modules` to $paths.vendor
gulp.task('copy-npm-dependencies', () => {
return gulp.src(gnf(), {base:'./'})
.pipe(gulp.dest(paths.vendor));
});
// Move `$paths.vendor/node_modules/**/*` to `$paths.vendor/**/*`
gulp.task('copy-vendor-dependencies', ['copy-npm-dependencies'], () => {
return gulp.src(paths.vendor + 'node_modules/**/*')
.pipe(gulp.dest(paths.vendor));
});
// Delete `$paths.vendor/node_modules`
gulp.task('dependencies', ['copy-vendor-dependencies'], () => {
return del([paths.vendor + 'node_modules/']);
});
// ---
// Symbols
// ---
// Convert multiple svg's to one symbol file
// https://css-tricks.com/svg-symbol-good-choice-icons/
gulp.task('symbols', () => {
return gulp.src(paths.symbolsSrc)
.pipe(cheerio(config.cheerio))
.pipe(svgmin())
.pipe(svgSymbols(config.symbols))
.pipe(gulp.dest(paths.symbolsDist));
});
// ---
// CSS
// ---
// Generate css > 'gulp css'
gulp.task('css', () => {
return gulp.src(paths.scssSrc)
.pipe(sass.sync(config.sass).on('error', sass.logError))
.pipe(postcss([ autoprefixer(config.autoprefixer) ]))
.pipe(gulp.dest(paths.cssDist))
.pipe(browserSync.stream())
.pipe(gulp.dest(paths.cssSrc));
});
// Production css > 'gulp productioncss'
gulp.task('productioncss', () => {
return gulp.src(paths.scssSrc)
.pipe(sass.sync(config.sass).on('error', sass.logError))
.pipe(postcss([ autoprefixer(config.autoprefixer) ]))
.pipe(cleanCSS(config.cleancss))
.pipe(rename((path) => {
path.basename += ".min";
}))
.pipe(gulp.dest(paths.cssSrc));
});
// ---
// Javascript
// ---
// Concat JS > 'gulp js'
gulp.task('js', () => {
return gulp.src(paths.jsSrc)
// .pipe(babel({
// presets: ['es2017-node7']
// }))
.pipe(concat(config.jsConcat))
.pipe(gulp.dest(paths.jsJekyllDist))
.pipe(browserSync.stream())
.pipe(gulp.dest(paths.jsDist));
});
// Compress and concat JS > 'gulp productionjs'
gulp.task('productionjs', () => {
return gulp.src(paths.jsSrc)
// .pipe(babel({
// presets: ['es2017-node7']
// }))
.pipe(concat(config.minifyjsConcat))
.pipe(uglify())
.pipe(gulp.dest(paths.jsDist));
});
// ---
// Jekyll
// ---
// Jekyll staging build > 'gulp jekyll'
gulp.task('jekyll', shell.task([
'bundle exec jekyll build --incremental',
]))
// // Jekyll production build > 'gulp jekyllBuild'
gulp.task('jekyllBuild', shell.task([
'JEKYLL_ENV=production bundle exec jekyll build',
]))
// ---
// Browsersync
// ---
// Browsersync > 'gulp browsersync'
gulp.task('browsersync', () => {
browserSync.init(config.browsersync);
});
// Browsersync reload after Jekyll build > 'gulp browsersyncReload'
gulp.task('browsersyncReload', ['jekyll'], () => {
browserSync.reload();
});
// ---
// Main tasks
// ---
// Default task > 'gulp'
gulp.task('default', function(callback) {
sequence(
'assets',
'jekyll',
callback);
});
// Build task > 'gulp build'
gulp.task('build', function(callback) {
sequence(
'production',
'jekyllBuild',
callback);
});
// Assets task > 'gulp assets'
gulp.task('assets', function(callback) {
sequence(
'dependencies',
['css', 'js', 'symbols'],
callback);
});
// Production task > 'gulp production'
gulp.task('production', function(callback) {
sequence(
'dependencies',
[
'productioncss',
'productionjs',
'symbols'
],
callback);
});
// Watch task > 'gulp watch'
gulp.task('watch', ['default','browsersync'],() => {
gulp.watch(paths.jsWatch, ['js']);
gulp.watch(paths.cssWatch, ['css']);
gulp.watch(paths.symbolsWatch, ['symbols']);
gulp.watch(paths.siteWatch, ['browsersyncReload']);
});