|
6 | 6 | module.exports = function (gulp, $, options) { |
7 | 7 |
|
8 | 8 | var path = require('path'), |
9 | | - productionPipe = $.util.noop, |
10 | 9 | paths = options.paths, |
11 | | - filesMatch = '**/*.{png,jpg,gif,svg,webp}'; |
| 10 | + filesMatch = '**/*.{png,jpg,gif,svg,webp}', |
| 11 | + plugins = []; |
| 12 | + |
| 13 | + plugins.push($.imagemin.svgo({ |
| 14 | + plugins: [ |
| 15 | + {cleanupIDs: false}, |
| 16 | + {removeViewBox: false} |
| 17 | + ] |
| 18 | + })); |
| 19 | + |
| 20 | + if (options.production) { |
| 21 | + plugins.push( |
| 22 | + $.imagemin.jpegtran({progressive: false}), |
| 23 | + $.imagemin.gifsicle({interlaced: true}), |
| 24 | + $.imagemin.optipng() |
| 25 | + ); |
| 26 | + } |
12 | 27 |
|
13 | 28 | gulp.task('images', function () { |
14 | 29 |
|
15 | | - if (options.production) { |
16 | | - productionPipe = require('lazypipe')() |
17 | | - .pipe($.imagemin, { |
18 | | - progressive: false, |
19 | | - interlaced: true, |
20 | | - svgoPlugins: [{ |
21 | | - cleanupIDs: false, |
22 | | - removeViewBox: false |
23 | | - }] |
24 | | - }) |
25 | | - .pipe($.rev); |
26 | | - } |
27 | | - |
28 | 30 | return gulp.src(options.assetsPath('src.images', filesMatch)) |
29 | | - .pipe($.changed(options.assetsPath('dist.images'))) |
30 | | - .pipe($.if('*.svg', $.imagemin({ |
31 | | - svgoPlugins: [{ |
32 | | - cleanupIDs: false, |
33 | | - removeViewBox: false |
34 | | - }] |
35 | | - }))) |
36 | | - .pipe($.if(options.production, productionPipe())) |
37 | | - .pipe( |
38 | | - gulp.dest(options.assetsPath('dist.images')) |
39 | | - ) |
| 31 | + .pipe($.imagemin(plugins)) |
| 32 | + .pipe($.if(options.production, $.rev())) |
| 33 | + .pipe(gulp.dest(options.assetsPath('dist.images'))) |
40 | 34 | .pipe($.if(options.production, $.rev.manifest(path.join(paths.dist.root, paths.dist.revmap), {merge: true}))) |
41 | 35 | .pipe($.if(options.production, gulp.dest('.'))) |
42 | 36 | .pipe($.if(options.isWatching, $.notify({ message: 'Images Processed', onLast: true }))) |
43 | 37 | .pipe($.size({title: 'images'})); |
44 | | - |
45 | 38 | }); |
46 | 39 |
|
47 | 40 | }; |
|
0 commit comments