-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
81 lines (72 loc) · 1.97 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
const gulp = require('gulp');
const gulpIf = require('gulp-if');
const yaml = require('gulp-yaml');
const htmlMinifier = require('gulp-html-minifier-terser');
const imageResize = require('gulp-image-resize');
const imagemin = require('gulp-imagemin');
const pngquant = require('imagemin-pngquant');
const webp = require('imagemin-webp');
const del = require('delete');
const { mozjpeg, svgo } = 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')
);