npm install --save-dev gulp-tinypng-nokey
在目录下新建gulpfile.js,然后写入以下代码,执行gulp tinypng命令压缩
var gulp = require('gulp');
var tiny = require('gulp-tinypng-nokey');
let date = new Date()
let h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
let m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
let now = h + '' + m + '' + s
gulp.task('tinypng', function(cb) {
gulp.src('img/*')
.pipe(tiny())
.pipe(gulp.dest('dist/'+now));
});