-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
116 lines (104 loc) · 2.76 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const gulp = require('gulp'),
gulpLoadPlugins = require('gulp-load-plugins'),
plugins = gulpLoadPlugins(),
del = require('del'),
path = require('path'),
imageminJpegRecompress = require('imagemin-jpeg-recompress'),
imageminPngquant = require('imagemin-pngquant')
const pluginSrc = {
js: [
'public/js/*.js',
'!public/js/*.min.js',
'!public/js/vendor/**/*.js',
],
css: [
'public/css/*.less',
'!public/css/vendor/**/*.less',
],
cssMaps: [
'public/css/maps/*',
],
images: [
'public/images/**/*.svg',
'public/images/**/*.png',
'public/images/**/*.jpeg',
'public/images/**/*.jpg',
],
lang: {
src: [
'**/*.php',
'!vendor/**/*.php',
],
dest: './languages/',
},
}
gulp.task('images', function () {
return gulp.src(pluginSrc.images).
pipe(plugins.plumber()).
pipe(plugins.imagemin([
plugins.imagemin.gifsicle({ interlaced: true }),
imageminJpegRecompress({
progressive: true,
max: 80,
min: 70,
}),
imageminPngquant({
quality: [0.5, 0.8],
}),
plugins.imagemin.svgo({ plugins: [{ removeViewBox: true }] }),
])).
pipe(gulp.dest(function (file) {
return file.base
})).
pipe(plugins.notify({ message: 'Изображения оптимизированы' }))
})
gulp.task('i18n', function () {
return gulp.src(pluginSrc.lang.src).pipe(plugins.sort()).pipe(plugins.wpPot({
package: path.basename(__dirname),
})).pipe(plugins.rename({
basename: path.basename(__dirname),
extname: '.pot',
})).pipe(gulp.dest(pluginSrc.lang.dest))
})
gulp.task('clean', function (cb) {
del(pluginSrc.cssMaps, cb)
})
let js = function (path) {
return gulp.src(path).pipe(plugins.plumber()).pipe(plugins.uglify({
compress: true,
})).pipe(plugins.rename({
extname: '.js',
suffix: '.min',
})).pipe(gulp.dest(function (file) {
return file.base
})).pipe(plugins.notify({ message: 'Скрипты плагина собрались' }))
}
gulp.task('js', function (done) {
js(pluginSrc.js)
done()
})
let css = function (path) {
return gulp.src(path).
pipe(plugins.sourcemaps.init({ loadMaps: true })).
pipe(plugins.plumber()).
pipe(plugins.less()).
pipe(plugins.autoprefixer(['ios_saf >= 6', 'last 3 versions'])).
pipe(plugins.csso()).
pipe(gulp.dest(function (file) {
return file.base
})).
pipe(plugins.sourcemaps.write()).
pipe(plugins.notify({ message: 'Стили плагина собрались' }))
}
gulp.task('css', function (done) {
css(pluginSrc.css)
done()
})
gulp.task('watch', function () {
gulp.watch(pluginSrc.js).on('change', function (file) {
js(file)
})
gulp.watch(pluginSrc.css).on('change', function (file) {
css(file)
})
})