-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
73 lines (64 loc) · 1.67 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
'use strict';
const gulp = require('gulp');
const newer = require('gulp-newer');
const imageResize = require('gulp-image-resize')
const imagemin = require('gulp-imagemin');
const jpegrecompress = require('imagemin-jpeg-recompress');
const mozjpeg = require('imagemin-mozjpeg')
var IMG_SRC = 'images/*.{jpg,png,gif,svg}';
var IMG_NORES_SRC = 'images_noresize/*.{jpg,png,gif}';
var IMG_DST = '../static/images/';
var IMG_W = 600;
var FAV_SRC = 'favicons/**/*';
var FAV_DST = '../static/';
var opts_jpegrecompress = {
accurate: true,
quality: 'medium',
method: 'ms-ssim',
loops: 6,
progressive: true,
subsample: 'default',
strip: true
}
var opts_mozjpeg = {
quality: 60,
progressive: true
}
var plugins_imagemin = [
jpegrecompress(opts_jpegrecompress),
// mozjpeg(opts_mozjpeg),
imagemin.optipng({optimizationLevel: 5}),
imagemin.gifsicle({interlaced: true}),
imagemin.svgo({
plugins: [
{removeViewBox: true},
{cleanupIDs: false}
]
})
]
var opts_imagemin = {
verbose: true
}
var opts_imageResize = {
imageMagick: true,
width: IMG_W
}
gulp.task('images', function () {
return gulp.src(IMG_SRC)
// .pipe(newer(IMG_DST))
.pipe(imageResize(opts_imageResize))
.pipe(imagemin(plugins_imagemin, opts_imagemin))
.pipe(gulp.dest(IMG_DST))
});
gulp.task('images_noresize', function () {
return gulp.src(IMG_NORES_SRC)
.pipe(imagemin(plugins_imagemin, opts_imagemin))
.pipe(gulp.dest(IMG_DST))
});
gulp.task('favicons', function () {
return gulp.src(FAV_SRC)
.pipe(newer(FAV_DST))
.pipe(imagemin(plugins_imagemin, opts_imagemin))
.pipe(gulp.dest(FAV_DST))
});
gulp.task('default', ['images', 'images_noresize', 'favicons']);