Skip to content

Instantly share code, notes, and snippets.

@qant
Created March 9, 2021 13:39
Show Gist options
  • Select an option

  • Save qant/c68c71d3449bba1e00ebff127e7929bd to your computer and use it in GitHub Desktop.

Select an option

Save qant/c68c71d3449bba1e00ebff127e7929bd to your computer and use it in GitHub Desktop.
Gulp image compression for Page Speed of Google, 37% of compression aprox.
install node
install npm
put package.json
npm i
create _src/ and dest/ folders
put image files to _src/ folder
then "npx gulp" to run
var gulp = require('gulp'),
imagemin = require('gulp-imagemin'),
imageminJpegRecompress = require('imagemin-jpeg-recompress'),
imageminPngquant = require('imagemin-pngquant'),
newer = require('gulp-newer'),
debug = require('gulp-debug');
exports.default = () => (
gulp.src('_src/**/*')
.pipe(newer('dest'))
.pipe(imagemin([
imageminJpegRecompress({
progressive: true,
min: 70, max: 75
}),
imageminPngquant({quality: [0.7, 0.75]})
]))
.pipe(debug({
title: 'Processing:',
showCount: false
}))
.pipe(gulp.dest('dest'))
);
{
"name": "desktop",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gulp": "^4.0.2",
"gulp-debug": "^4.0.0",
"gulp-imagemin": "^7.1.0",
"gulp-newer": "^1.4.0",
"imagemin-jpeg-recompress": "^7.0.0",
"imagemin-pngquant": "^9.0.1"
},
"dependencies": {
"gulp-cli": "^2.3.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment