Created
March 9, 2021 13:39
-
-
Save qant/c68c71d3449bba1e00ebff127e7929bd to your computer and use it in GitHub Desktop.
Gulp image compression for Page Speed of Google, 37% of compression aprox.
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
| 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 |
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
| 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')) | |
| ); |
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
| { | |
| "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