文章目录
  1. 1. image-resize压缩尺寸
  2. 2. gulp-imagemin品质压缩

网页性能优化,通常要处理图片,尤其图片量大的时候,更需要工具来批量处理,这里使用gulp。

image-resize压缩尺寸

1
2
3
4
5
6
7
8
9
10
var gulp = require('gulp');
var imageResize = require('gulp-image-resize');

gulp.task('resize', function() {
return gulp.src('./images/**/*')
.pipe(imageResize({
width: 400
}))
.pipe(gulp.dest('dist/resize'));
});

gulp-imagemin品质压缩

1
2
3
4
5
6
7
8
9
10
11
12
13
var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
gulp.task('min', function() {
return gulp.src('./images/**/*')
.pipe(imagemin({
progressive: true,
use: [pngquant({
quality: '65-80'
})]
}))
.pipe(gulp.dest('dist/min'));
})
文章目录
  1. 1. image-resize压缩尺寸
  2. 2. gulp-imagemin品质压缩
顶部