Created
March 29, 2016 16:54
-
-
Save yaronuliel/2f076e49f92998893f1b4004ebf9de6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const fs = require('fs'); | |
const path = require('path'); | |
function error(message) { | |
console.error(message); | |
process.exit(); | |
} | |
if (process.argv.length != 4) { | |
error("Use: shrink FROM_PATH TO_PATH"); | |
} | |
var from = path.resolve(process.argv[2]); | |
var to = path.resolve(process.argv[3]); | |
if(!fs.existsSync(from) || !fs.lstatSync(from).isDirectory()) { | |
error(process.argv[2] + " is not a valid directory"); | |
} | |
if(!fs.existsSync(to) || !fs.lstatSync(to).isDirectory()) { | |
error(process.argv[3] + " is not a valid directory"); | |
} | |
const gulp = require('gulp'); | |
const imagemin = require('gulp-imagemin'); | |
const pngquant = require('imagemin-pngquant'); // $ npm i -D imagemin-pngquant | |
gulp.task('default', function(){ | |
return gulp.src([from + '/**/*.png',from + '/**/*.jpg',from + '/**/*.jpeg',from + '/**/*.gif']) | |
.pipe(imagemin({ | |
progressive: true, | |
svgoPlugins: [ | |
{removeViewBox: false}, | |
{cleanupIDs: false} | |
], | |
use: [pngquant()] | |
})) | |
.pipe(gulp.dest(to)); | |
}); | |
gulp.start('default'); | |
console.log('Starting to minify png and jpg from ' + from); |
Author
yaronuliel
commented
Mar 29, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment