1 |
|
2 | 'use strict';
|
3 | var gulp = require('gulp');
|
4 | var extToGlob = require('../lib/ext-to-glob');
|
5 | var unlink = require('../lib/unlink');
|
6 | var compileImage = require('../compiler/compress-image');
|
7 | var watchLog = require('../log/watch');
|
8 |
|
9 | var IMAGE_EXTS = ['png', 'jpg', 'jpeg', 'svg', 'gif',];
|
10 |
|
11 |
|
12 | function compress(config) {
|
13 | |
14 |
|
15 |
|
16 | return function (file) {
|
17 | return compileImage(file, config.src, config.dist);
|
18 | }
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | exports.build = function (config) {
|
25 | return function () {
|
26 | return compress(config)(extToGlob(config, IMAGE_EXTS));
|
27 | };
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | exports.watch = function (config) {
|
34 | return function (cb) {
|
35 | var glob = extToGlob(config, IMAGE_EXTS);
|
36 | watchLog('image', glob)
|
37 | gulp.watch(glob)
|
38 | .on('change', compress(config))
|
39 | .on('add', compress(config))
|
40 | .on('unlink', unlink(config.src, config.dist));
|
41 | cb && cb();
|
42 | }
|
43 | } |
\ | No newline at end of file |