imagemin-keep-folder

Minify images

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
imagemin-keep-folder
5.3.26 years ago6 years agoMinified + gzip package size for imagemin-keep-folder in KB

Readme

Minify images seamlessly

Introduction

Fork form imagemin.
support keep and customize folder structure

Install

``` $ npm install --save-dev imagemin-keep-folder ```

Usage

```js // as usual const imagemin = require('imagemin-keep-folder'); imagemin('images/.{jpg,png}', 'build/images', { }).then(files => {
console.log(files);
//=> [{data: <Buffer 89 50 4e …>, path: 'build/images/foo.jpg'}, …]
}); ``` ```js // keep folder structure as input const imagemin = require('imagemin-keep-folder'); imagemin('images//.{jpg,png}', { }); // for example // images/a.jpg => images/a.jpg // images/foo/a.jpg => images/foo/a.jpg // images/foo/bar/a.jpg => images/foo/bar/a.jpg ``` ```js // keep folder structure as input use imagemin-webp const imagemin = require('imagemin-keep-folder'); const imageminWebp = require("imagemin-webp"); imagemin('images//.{jpg,png}', { use:
imageminWebp({})
}); // for example // images/a.jpg => images/a.webp // images/foo/a.jpg => images/foo/a.webp // images/foo/bar/a.jpg => images/foo/bar/a.webp ``` ```js // customize folder structure as input use imagemin-webp const imagemin = require('imagemin-keep-folder'); const imageminWebp = require("imagemin-webp"); imagemin('images//.{jpg,png}', { use:
imageminWebp({})
, replaceOutputDir: output => {
return output.replace(/images\//, '.webp/')
} }); // for example // images/a.jpg => .webp/a.webp // images/foo/a.jpg => .webp/foo/a.webp // images/foo/bar/a.jpg => .webp/foo/bar/a.webp ```

API

same as imagemin

imagemin(input, output, options)

Returns Promise<Object[]> in the format {data: Buffer, path: String}.

input

Type: Array Files to be optimized. See supported minimatch patterns.

output

Type: string Set the destination folder to where your files will be written. If no destination is specified no files will be written. If no destination is specified, files will be written and keep folder structure

options

Type: Object
replaceOutputDir (new options)
Type: Function Returns String (new output dir)
plugins
Type: Array Plugins to use.

imagemin.buffer(buffer, options)

Returns Promise<Buffer>.

buffer

Type: Buffer Buffer to optimize.

options

Type: Object
plugins
Type: Array Plugins to use.

Related

License

MIT © imagemin