-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
179 lines (164 loc) · 4.95 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
import gulp from "gulp";
import minifyHtml from "gulp-minify-html";
import uglify from "gulp-uglify";
import concat from "gulp-concat";
import fs from "fs";
import webp from "gulp-webp";
import template from "gulp-template-html";
import browserSync from "browser-sync";
import superstatic from "superstatic";
import workboxBuild from "workbox-build";
import cleanCSS from "gulp-clean-css";
import image from "gulp-image";
gulp.task('copy', function () {
return gulp.src(['src/**/*', '!src/images/*', '!src/robots/images/**/*']).
pipe(gulp.dest('dist'));
});
gulp.task('template-html', function () {
return gulp.src([
'dist/index.html',
'dist/404.html',
'dist/achievements.html',
'dist/calendar.html',
'dist/downloads.html',
'dist/about.html',
'dist/join.html',
'dist/live.html',
'dist/media.html',
'dist/resources.html',
'dist/thanks.html',
'dist/azscout.html',
'dist/ocscout.html',
'dist/sponsors.html',
]).pipe(template('src/template.html')).pipe(gulp.dest('dist'));
});
gulp.task('minify-html', function () {
return gulp.src('dist/**/*.html').pipe(minifyHtml()).pipe(gulp.dest('dist'));
});
gulp.task('merge-minify-js-css', function () {
gulp.src(['src/assets/js/*.js', '!src/assets/js/workbox-sw.js']).
pipe(uglify()).
pipe(gulp.dest('dist/assets/js'));
return gulp.src('src/assets/css/*.css')
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(gulp.dest('dist/assets/css'));
});
gulp.task('compress-images-fast', function () {
return gulp.src('src/images/*').pipe(image({
pngquant: true,
optipng: false,
zopflipng: true,
jpegRecompress: false,
mozjpeg: true,
guetzli: false,
gifsicle: true,
svgo: true,
concurrent: 10,
quiet: false,
options: {
optipng: ['-i 1', '-strip all', '-fix', '-o2', '-force'],
pngquant: ['--speed=8', '--force', 256],
zopflipng: ['-y', '--lossy_8bit', '--lossy_transparent'],
jpegRecompress: ['--strip', '--quality', 'medium', '--min', 40, '--max', 80],
mozjpeg: ['-optimize', '-progressive'],
guetzli: ['--quality', 85],
gifsicle: ['--optimize'],
svgo: ['--enable', 'cleanupIDs', '--disable', 'convertColors'],
},
})).pipe(gulp.dest('dist/images'));
});
gulp.task('compress-images', function () {
gulp.src('src/images/*').pipe(image({
pngquant: true,
optipng: false,
zopflipng: true,
jpegRecompress: false,
mozjpeg: true,
guetzli: true,
gifsicle: true,
svgo: true,
concurrent: 10,
quiet: false,
options: {
optipng: ['-i 1', '-strip all', '-fix', '-o7', '-force'],
pngquant: ['--speed=1', '--force', 256],
zopflipng: ['-y', '--lossy_8bit', '--lossy_transparent'],
jpegRecompress: [
'--strip',
'--quality',
'medium',
'--min',
,
'--max',
80
],
mozjpeg: ['-optimize', '-progressive'],
guetzli: ['--quality', 85],
gifsicle: ['--optimize'],
svgo: ['--enable', 'cleanupIDs', '--disable', 'convertColors'],
},
})).pipe(gulp.dest('dist/images'));
return gulp.src('src/robots/images/**/*').pipe(image({
pngquant: true,
optipng: true,
zopflipng: true,
jpegRecompress: true,
mozjpeg: true,
guetzli: true,
gifsicle: true,
svgo: true,
concurrent: 10,
quiet: false,
options: {
optipng: ['-i 1', '-strip all', '-fix', '-o7', '-force'],
pngquant: ['--speed=1', '--force', 256],
zopflipng: ['-y', '--lossy_8bit', '--lossy_transparent'],
jpegRecompress: [
'--strip',
'--quality',
'medium',
'--min',
50,
'--max',
80
],
mozjpeg: ['-optimize', '-progressive'],
guetzli: ['--quality', 85],
gifsicle: ['--optimize'],
svgo: ['--enable', 'cleanupIDs', '--disable', 'convertColors'],
},
})).pipe(gulp.dest('dist/robots/images'));
});
gulp.task('service-worker', () => {
return workboxBuild.injectManifest({
swSrc: 'src/sw.js',
swDest: 'dist/sw.js',
globDirectory: 'dist',
globPatterns: [
'**\/*.{js,css,html,png,jpg,jpeg,gif,svg}',
]
});
});
gulp.task('reload', gulp.series('copy', 'template-html', 'service-worker'));
// create a task that ensures the `js` task is complete before
// reloading browsers
gulp.task('js-watch', gulp.series('reload', function (done) {
browserSync.reload();
done();
}));
// use default task to launch Browsersync and watch JS files
gulp.task('serve', gulp.series('reload', function () {
// Serve files from the root of this project
browserSync.init({
server: {
baseDir: 'dist/',
middleware: [superstatic({
stack: 'strict'
})]
},
});
// add browserSync.reload to the tasks array to make
// all browsers reload after tasks are complete.
gulp.watch('src/**/*', gulp.series('js-watch'));
}));
gulp.task('default', gulp.series('copy','compress-images-fast','template-html', 'minify-html', 'merge-minify-js-css', 'service-worker'));