-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
80 lines (72 loc) · 1.93 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
import gulp from 'gulp';
import gulpIf from 'gulp-if';
import yaml from 'gulp-yaml';
import htmlMinifier from 'gulp-html-minifier-terser';
import imageResize from 'gulp-image-resize';
import imagemin from 'gulp-imagemin';
import pngquant from 'imagemin-pngquant';
import webp from 'imagemin-webp';
import del from 'delete';
import { mozjpeg,svgo } from 'gulp-imagemin';
const configs = {
htmlMinifier: {
minifyCSS: true,
minifyJS: true,
removeComments: true,
collapseWhitespace: true,
},
imageResize: {
width: 128,
crop: false,
imageMagick: true,
},
mozjpeg: {},
pngquant: {
strip: true,
verbose: true,
},
webp: {},
svgo: {
plugins: ['preset-default'],
},
};
gulp.task('clean-dist', () => del('dist'));
gulp.task('build-json', () =>
gulp.src('./src/*.yml').pipe(yaml()).pipe(gulp.dest('dist'))
);
gulp.task('minify-html', () =>
gulp
.src('src/**/*.html')
.pipe(htmlMinifier(configs.htmlMinifier))
.pipe(gulp.dest('dist'))
);
gulp.task('minify-image', () =>
gulp
.src('src/img/**/*.{png,jpg,gif,svg,webp}')
.pipe(
gulpIf(
(file) => !/\.svg$/i.test(file.path),
imageResize(configs.imageResize)
)
)
.pipe(
imagemin(
[
mozjpeg(configs.mozjpeg),
pngquant(configs.pngquant),
webp(configs.webp),
svgo(configs.svgo),
],
{
verbose: true,
}
)
)
.pipe(gulp.dest('dist/img'))
);
gulp.task('copy-files', () => gulp.src('public/**').pipe(gulp.dest('dist')));
gulp.task('build', gulp.parallel('build-json', 'minify-html', 'minify-image'));
gulp.task(
'default',
gulp.series('clean-dist', gulp.parallel('build'), 'copy-files')
);