-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
64 lines (58 loc) · 1.77 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
const gulp = require('gulp'),
gic = require('gulp-imgconv'),
image = require('gulp-image'),
gulpif = require('gulp-if'),
rename = require("gulp-rename"),
argv = require('yargs').argv,
del = require('del');
var output = argv.output,
resize = (argv.resize === undefined) ? false : true,
width = (argv.width) ? argv.width : 1000,
height = (argv.height) ? argv.height : 1000,
fit = (argv.fit) ? argv.fit : "contain",
bg = (argv.bg) ? argv.bg : "#ffffffff",
q = (argv.q) ? argv.q : 80;
if (output == "jpg") { output = "jpeg" }
gulp.task('convert', function () {
var stream = gulp.src('src/**/*')
.pipe(gulpif(resize, gic(gic
.begin()
.resize({
width: width,
height: height,
fit: fit,
background: bg
})
.commit()
)))
.pipe(gulpif(output !== undefined, gic(gic
.begin()
.toFormat(output, { quality: q })
.commit()
)))
.pipe(gulpif(output === "jpeg", rename({
extname: ".jpg"
})))
.pipe(gulp.dest('dest/'));
return stream;
});
gulp.task('compress', function () {
var stream = gulp.src('dest/**/*')
.pipe(image({
pngquant: true,
optipng: false,
zopflipng: false,
jpegRecompress: true,
mozjpeg: false,
guetzli: false,
gifsicle: false,
svgo: true,
concurrent: 10
}))
.pipe(gulp.dest('./images'));
return stream;
});
gulp.task('clean', function () {
return del(['dest/**', 'images/**', 'src/**'], { force: true });
});
gulp.task('images', gulp.series('convert', 'compress'));