forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminify.js
More file actions
executable file
·44 lines (34 loc) · 1008 Bytes
/
minify.js
File metadata and controls
executable file
·44 lines (34 loc) · 1008 Bytes
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
const pngquant = require('imagemin-pngquant');
const path = require('path');
const gulp = require('gulp');
const gp = require('gulp-load-plugins')();
const gutil = require('gulp-util');
const fs = require('fs');
/**
*
* @param options
* options.root => the root to import from
* @returns {Function}
*/
module.exports = function(options) {
options = options || {};
const root = options.root || require('yargs').argv.root;
if (!root) {
throw new Error("Root not set");
}
return function(callback) {
gutil.log("minify " + root);
// When enable: CHECK demo.svg (!!!)
// it has JS inside!!! svgo breaks it by removing t-template-path
return gulp.src(root + '/**/*.{png,jpg,gif}')
//return gulp.src(root + '/**/*.{svg,png,jpg,gif}')
.pipe(gp.debug())
.pipe(gp.imagemin({
verbose: true,
progressive: true,
// svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(root));
};
};