-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
93 lines (93 loc) · 2.96 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
const { src, dest, watch } = require('gulp')
const imagemin = require('gulp-imagemin')
const webp = require('gulp-webp')
const ImageminMozjpeg = require('imagemin-mozjpeg')
const svgSprite = require('gulp-svg-sprite')
const paths = { img: 'src/assets/img' }
/****************************************************************************************************/
// IMG MINIFY
/****************************************************************************************************/
const minifyImage = (file) =>
src(file, { base: 'src/assets/img/' })
.pipe(imagemin([
imagemin.gifsicle({ interlaced: true }),
ImageminMozjpeg({ quality: 75, progressive: true }),
imagemin.optipng({ optimizationLevel: 5 })
]))
.pipe(dest(paths.img))
/****************************************************************************************************/
// IMG TO WEBP
/****************************************************************************************************/
const convertToWebp = (file) => {
src(file, { base: 'src/assets/img/' })
.pipe(webp())
.pipe(dest(paths.img))
}
/****************************************************************************************************/
// SVG SPRITE ICONS TASK
/****************************************************************************************************/
const config = {
shape: {
dimension: {
maxWidth: 50,
maxHeight: 50
},
spacing: {
padding: 0,
box: 'icon'
},
transform: [
{
svgo: {
plugins: [
{ removeXMLNS: true },
{ cleanupListOfValues: true },
{ convertShapeToPath: false },
{ removeAttrs: { attrs: ['data-name', 'version'] } },
{ removeStyleElement: true },
{ removeScriptElement: true }
],
floatPrecision: 1
}
}
]
},
svg: {
xmlDeclaration: false,
doctypeDeclaration: false,
dimensionAttributes: false
},
mode: {
stack: {
dest: '.',
sprite: 'img/sprite.svg',
render: {
css: {
template: 'src/templates/icon_template.html',
dest: 'css/modules/sprite.css'
}
}
}
}
}
const svgicons = () =>
src('src/assets/icons/*.svg')
.pipe(svgSprite(config))
.pipe(dest('src/assets'))
exports.svgicons = svgicons
/****************************************************************************************************/
// WATCHERS
/****************************************************************************************************/
exports.watchers = cb => {
watch(['src/assets/img/**/*.{jpg,png,gif}'])
.on('add', (path) => {
console.log('Добавлена картинка')
console.log(path)
convertToWebp(path)
console.log('Картинка сконвертирована в формат webp')
minifyImage(path)
console.log('Картинка минифицирована')
})
watch('src/assets/icons/*.svg', svgicons)
cb()
}