forked from lechoo/toddmotto.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
73 lines (62 loc) · 1.85 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import util from 'gulp-util';
import concat from 'gulp-concat';
import header from 'gulp-header';
import plumber from 'gulp-plumber';
import babel from 'gulp-babel';
import uglify from 'gulp-uglify';
import addsrc from 'gulp-add-src';
import autoprefixer from 'gulp-autoprefixer';
import browserSync from 'browser-sync';
import child from 'child_process';
import hygienist from 'hygienist-middleware';
import del from 'del';
import fs from 'fs';
const parsed = JSON.parse(fs.readFileSync('./package.json'));
const siteRoot = '_site';
const jekyllLogger = buffer => {
buffer.toString().split(/\n/).forEach((message) => util.log(`Jekyll: ${message}`));
};
const banner = (
`/*! toddmotto.com | Todd Motto (c) ${new Date().getFullYear()} */\n`
);
const paths = {
scripts: '_scripts/*.js',
libs: [
'node_modules/linkjuice/dist/linkjuice.js'
],
dist: 'js/'
};
browserSync.create();
gulp.task('clean', fn => del([paths.dist, siteRoot], fn));
gulp.task('scripts', ['clean'], () => {
return gulp.src(paths.scripts)
.pipe(plumber())
.pipe(babel())
.pipe(addsrc.prepend(paths.libs))
.pipe(concat('bundle.min.js'))
.pipe(uglify())
.pipe(header(banner, {
parsed
}))
.pipe(gulp.dest(paths.dist));
});
gulp.task('jekyll', () => {
const jekyll = child.spawn('jekyll', ['serve', '--watch', '--incremental', '--drafts']);
jekyll.stdout.on('data', jekyllLogger);
jekyll.stderr.on('data', jekyllLogger);
});
gulp.task('serve', () => {
browserSync.init({
files: [`${siteRoot}/**`],
port: 4000,
server: {
baseDir: siteRoot,
middleware: hygienist(siteRoot)
}
});
});
gulp.task('watch', () => {
gulp.watch(paths.scripts, ['scripts']);
});
gulp.task('default', ['scripts', 'serve', 'jekyll', 'watch']);