-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
56 lines (51 loc) · 1.79 KB
/
index.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
var gulp = require('gulp');
var changed = require('gulp-changed');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var _ = require('underscore');
var elixir = require('laravel-elixir');
var config = elixir.config;
/*
|----------------------------------------------------------------
| ImageMin Processor
|----------------------------------------------------------------
|
| This task will trigger your images to be processed using
| imagemin processor.
|
| Minify PNG, JPEG, GIF and SVG images
|
*/
elixir.extend('imagemin', function(options) {
config.images = _.extend({
folder: 'images',
outputFolder: 'images'
}, config.images || {});
options = _.extend({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}, options);
new elixir.Task('imagemin', function () {
var paths = new elixir.GulpPaths()
.src(config.get('assets.images.folder'))
.output(config.get('public.images.outputFolder'));
return gulp.src(paths.src.path)
.pipe(changed(paths.output.path))
.pipe(imagemin(options))
.on('error', function(e) {
new elixir.Notification().error(e, 'ImageMin Failed!');
this.emit('end');
})
.pipe(gulp.dest(paths.output.path))
.pipe(new elixir.Notification('ImageMin Complete!'))
}).watch(
[
config.get('assets.images.folder') + '/**/*.jpg',
config.get('assets.images.folder') + '/**/*.jpeg',
config.get('assets.images.folder') + '/**/*.svg',
config.get('assets.images.folder') + '/**/*.gif',
config.get('assets.images.folder') + '/**/*.png'
]
);
});