This repository has been archived by the owner on Jun 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (52 loc) · 1.51 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
57
58
59
60
61
var Elixir = require('laravel-elixir');
var gulp = require('gulp');
var svgmin = require('gulp-svgmin');
var config = Elixir.config;
/*
|----------------------------------------------------------------
| SVG Task
|----------------------------------------------------------------
|
| This task will manage your SVG minfication.
|
*/
loadConfig();
Elixir.extend('svg', function(src, output, baseDir, options) {
var paths = getPaths(src, baseDir, output);
options = options || {};
new Elixir.Task('svg', function() {
return gulp.src(paths.src.path)
.pipe(svgmin(options.svgminOptions || config.svg.svgminOptions))
.on('error', function(e) {
new Elixir.Notification().error(e, 'SVG minification failed!');
this.emit('end');
})
.pipe(gulp.dest(paths.output.baseDir))
.pipe(new Elixir.Notification('SVG minified!'));
})
.watch(paths.src.path)
.ignore(paths.output.path);
});
/**
* Prep the Gulp src and output paths.
*
* @param {string|Array} src
* @param {string|null} baseDir
* @param {string|null} output
* @return {GulpPaths}
*/
function getPaths(src, baseDir, output) {
return new Elixir.GulpPaths()
.src(src, baseDir || config.get('assets.svg.folder'))
.output(output || config.get('public.svg.outputFolder'));
}
/**
* Load the default SVG config.
*/
function loadConfig() {
config.svg = {
folder: 'svg',
outputFolder: 'svg',
svgminOptions: {}
};
}