-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
146 lines (120 loc) · 4.36 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
'use strict';
var jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
var gulp = require('gulp'),
gutil = require('gulp-util'),
childprocess = require('child_process'),
runSequence = require('run-sequence');
var sass = require('gulp-sass'),
combineMq = require('gulp-combine-mq'),
autoprefixer = require('gulp-autoprefixer'),
cssnano = require('gulp-cssnano'),
shorthand = require('gulp-shorthand'),
bourbon = require('node-bourbon').includePaths,
neat = require('node-neat').includePaths;
var cheerio = require('gulp-cheerio'),
svgstore = require('gulp-svgstore'),
svgmin = require('gulp-svgmin'),
path = require('path');
var webPackStream = require('webpack-stream');
var browserSync = require('browser-sync');
// Paths -----------------------------------------------------------------------
var source = '.',
destination = './_site';
// Build -----------------------------------------------------------------------
gulp.task('jekyll-build', function (done) {
return childprocess.spawn( 'jekyll', ['build', '--config=_config.yml,_config_dev.yml'], {stdio: 'inherit'})
.on('close', done);
});
// Rebuild ---------------------------------------------------------------------
gulp.task('jekyll-rebuild', ['jekyll-build'] ,function () {
browserSync.reload();
});
// BrowserSync -----------------------------------------------------------------
gulp.task('browser-sync', ['jekyll-build'], function () {
browserSync({
notify: false,
server: {
baseDir: destination
},
ghostMode: {
clicks: false,
scroll: false,
forms: {
submit: false,
inputs: false,
toggles: false
}
}
});
});
// Sass ------------------------------------------------------------------------
gulp.task('stylesheets', function () {
return gulp.src(source + '/src/stylesheets/**/*.{scss,sass}')
.pipe(sass({
includePaths: bourbon,
includePaths: neat,
precision: 6
}).on('error', sass.logError))
// .pipe(combineMq())
// .pipe(shorthand())
.pipe(autoprefixer({
browsers: ['last 4 versions'],
cascade: false
}))
// .pipe(cssnano())
.pipe(gulp.dest(source + '/dist/css'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest(destination + '/dist/css'));
});
// Scripts ---------------------------------------------------------------------
gulp.task('scripts', function() {
return gulp.src(source + '/src/scripts/**/*.js')
.pipe(webPackStream(
require('./webpack.config.js')
))
.pipe(gulp.dest(source + '/dist/js'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest(destination + '/dist/js'));
});
// Icons -----------------------------------------------------------------------
gulp.task('icons', function () {
return gulp.src(source + '/src/icons/**/*.svg')
.pipe(svgmin(function (file) {
var prefix = path.basename(file.relative, path.extname(file.relative));
return {
plugins: [{
removeDoctype: true
}, {
removeComments: true
}, {
cleanupIDs: {
prefix: prefix + '-',
minify: false
}
}]
}
}))
.pipe(svgstore({ inlineSvg: true }))
.pipe(cheerio(function ($) {
$('[fill]').removeAttr('fill');
$('svg').attr('display', 'none');
}))
.pipe(gulp.dest(source + '/_includes'));
});
// Fonts -----------------------------------------------------------------------
gulp.task('fonts', function() {
return gulp.src(source + '/src/webfonts/**/*')
.pipe(gulp.dest(source + '/dist/webfonts'))
.pipe(gulp.dest(destination + '/dist/webfonts'));
});
// Watch -----------------------------------------------------------------------
gulp.task('watch', function () {
gulp.watch(source + '/src/stylesheets/**/*.{scss,sass}', ['stylesheets']);
gulp.watch(source + '/src/scripts/**/*.js', ['scripts']);
gulp.watch(source + '/src/icons/**/*.svg', ['icons', 'jekyll-rebuild']);
gulp.watch(source + '/**/*.{html,markdown,md}', ['jekyll-rebuild']);
})
// Default ---------------------------------------------------------------------
gulp.task('default', function(callback) {
runSequence(['stylesheets', 'scripts', 'icons', 'fonts'], 'browser-sync', 'watch', callback);
});