UNPKG

3.05 kBMarkdownView Raw
1# gulp-imagemin [![Build Status](https://travis-ci.com/sindresorhus/gulp-imagemin.svg?branch=master)](https://travis-ci.com/sindresorhus/gulp-imagemin) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)
2
3> Minify PNG, JPEG, GIF and SVG images with [`imagemin`](https://github.com/imagemin/imagemin)
4
5*Issues with the output should be reported on the [`imagemin` issue tracker](https://github.com/imagemin/imagemin/issues).*
6
7## Install
8
9```
10$ npm install --save-dev gulp-imagemin
11```
12
13## Usage
14
15### Basic
16
17```js
18const gulp = require('gulp');
19const imagemin = require('gulp-imagemin');
20
21exports.default = () => (
22 gulp.src('src/images/*')
23 .pipe(imagemin())
24 .pipe(gulp.dest('dist/images'))
25);
26```
27
28### Custom plugin options
29
30```js
31// …
32.pipe(imagemin([
33 imagemin.gifsicle({interlaced: true}),
34 imagemin.mozjpeg({quality: 75, progressive: true}),
35 imagemin.optipng({optimizationLevel: 5}),
36 imagemin.svgo({
37 plugins: [
38 {removeViewBox: true},
39 {cleanupIDs: false}
40 ]
41 })
42]))
43// …
44```
45
46Note that you may come across an older, implicit syntax. In versions < 3, the same was written like this:
47
48```js
49// …
50.pipe(imagemin({
51 interlaced: true,
52 progressive: true,
53 optimizationLevel: 5,
54 svgoPlugins: [
55 {
56 removeViewBox: true
57 }
58 ]
59}))
60// …
61```
62
63### Custom plugin options and custom `gulp-imagemin` options
64
65```js
66// …
67.pipe(imagemin([
68 imagemin.svgo({
69 plugins: [
70 {
71 removeViewBox: true
72 }
73 ]
74 })
75], {
76 verbose: true
77}))
78// …
79```
80
81## API
82
83Comes bundled with the following **lossless** optimizers:
84
85- [gifsicle](https://github.com/imagemin/imagemin-gifsicle) — *Compress GIF images*
86- [mozjpeg](https://github.com/imagemin/imagemin-mozjpeg) — *Compress JPEG images*
87- [optipng](https://github.com/imagemin/imagemin-optipng) — *Compress PNG images*
88- [svgo](https://github.com/imagemin/imagemin-svgo) — *Compress SVG images*
89
90These are bundled for convenience and most users will not need anything else.
91
92### imagemin(plugins?, options?)
93
94Unsupported files are ignored.
95
96#### plugins
97
98Type: `Array`\
99Default: `[imagemin.gifsicle(), imagemin.mozjpeg(), imagemin.optipng(), imagemin.svgo()]`
100
101[Plugins](https://www.npmjs.com/browse/keyword/imageminplugin) to use. This will completely overwrite all the default plugins. So, if you want to use custom plugins and you need some of defaults too, then you should pass default plugins as well. Note that the default plugins come with good defaults and should be sufficient in most cases. See the individual plugins for supported options.
102
103#### options
104
105Type: `object`
106
107##### verbose
108
109Type: `boolean`\
110Default: `false`
111
112Enabling this will log info on every image passed to `gulp-imagemin`:
113
114```
115gulp-imagemin: ✔ image1.png (already optimized)
116gulp-imagemin: ✔ image2.png (saved 91 B - 0.4%)
117```
118
119##### silent
120
121Type: `boolean`\
122Default: `false`
123
124Don't log the number of images that have been minified.
125
126You can also enable this from the command-line with the `--silent` flag if the option is not already specified.
127
\No newline at end of file