-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
executable file
·166 lines (146 loc) · 3.78 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
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
'use strict';
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import runSequence from 'run-sequence';
import browserSync from 'browser-sync';
import swPrecache from 'sw-precache';
const $ = gulpLoadPlugins();
// Minify the HTML.
gulp.task('minify-html', () => {
return gulp.src('_site/**/*.html')
.pipe($.htmlmin({
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeOptionalTags: true
}))
.pipe(gulp.dest('_site'));
});
// Optimize images.
gulp.task('minify-images', () => {
gulp.src('images/**/*')
.pipe($.imagemin({
progressive: true,
interlaced: true
}))
.pipe(gulp.dest('_site/images'));
});
// Concatenate, transpiles ES2015 code to ES5 and minify JavaScript.
gulp.task('scripts', () => {
gulp.src([
// Note: You need to explicitly list your scripts here in the right order
// to be correctly concatenated
'./_scripts/main.js'
])
.pipe($.concat('main.min.js'))
.pipe($.babel())
.pipe($.uglify({preserveComments: 'some'}))
.pipe(gulp.dest('scripts'));
});
// Minify and add prefix to css.
gulp.task('css', () => {
const AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
return gulp.src('css/main.css')
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
.pipe($.cssnano())
.pipe(gulp.dest('_site/css'));
});
// Compile scss to css.
gulp.task('scss', () => {
return gulp.src('scss/main.scss')
.pipe($.sass({
includePaths: ['css'],
onError: browserSync.notify
}))
.pipe(gulp.dest('css'));
});
// Pug (Jade) to HTML.
gulp.task('pug', () => {
return gulp.src([
'_includes-pug/**/*.pug',
'!_site/node_modules/**'
])
.pipe($.pug())
.pipe(gulp.dest('_includes'));
});
// Watch change in files.
gulp.task('serve', ['jekyll-build'], () => {
browserSync.init({
notify: false,
// Run as an https by uncommenting 'https: true'
// Note: this uses an unsigned certificate which on first access
// will present a certificate warning in the browser.
// https: true,
server: '_site',
port: 3000
});
// Warch html changes.
gulp.watch([
'css/**/*.css',
'scripts/**/*.js',
'_includes/**/*.html',
'_layouts/**/*.html',
'_posts/**/*.md',
'index.html'
], ['jekyll-build', browserSync.reload]);
// Watch Pug (Jade) changes.
gulp.watch('_includes-pug/**/*.pug', ['pug']);
// Watch scss changes.
gulp.watch('scss/**/*.scss', ['scss']);
// Watch JavaScript changes.
gulp.watch('_scripts/**/*.js', ['scripts']);
});
gulp.task('generate-service-worker', function(callback) {
var path = require('path');
var rootDir = '_site';
swPrecache.write(path.join(rootDir, 'sw.js'), {
staticFileGlobs: [rootDir + '/**/*.{js,html,css,png,jpg,gif,json}'],
stripPrefix: rootDir,
replacePrefix: '/BokBot.org'
}, callback);
});
gulp.task('jekyll-build', ['scripts', 'scss', 'pug'], $.shell.task([ 'jekyll build' ]));
// Default task.
gulp.task('build', () =>
runSequence(
'pug',
'scss',
'jekyll-build',
'minify-html',
'css',
'generate-service-worker',
'minify-images'
)
);
// Depoly website to gh-pages.
gulp.task('gh-pages', () => {
return gulp.src('./_site/**/*')
.pipe($.ghPages());
});
gulp.task('deploy', () => {
runSequence(
'pug',
'scss',
'jekyll-build',
'minify-html',
'css',
'generate-service-worker',
'minify-images',
'gh-pages'
)
});