Minify images seamlessly
Sindre Sorhus' open source work is supported by the community
Special thanks to:npm install imagemin
import imagemin from 'imagemin';
import imageminJpegtran from 'imagemin-jpegtran';
import imageminPngquant from 'imagemin-pngquant';
const files = await imagemin(['images/*.{jpg,png}'], {
destination: 'build/images',
plugins: [
imageminJpegtran(),
imageminPngquant({
quality: [0.6, 0.8]
})
]
});
console.log(files);
//=> [{data: <Uint8Array 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …]
Returns Promise<object[]>
in the format {data: Uint8Array, sourcePath: string, destinationPath: string}
.
Type: string[]
File paths or glob patterns.
Type: object
Type: string
Set the destination folder to where your files will be written. If no destination is specified, no files will be written.
Type: Array
The plugins to use.
Type: boolean
Default: true
Enable globbing when matching file paths.
Returns Promise<Uint8Array>
.
Type: Uint8Array
The image data to optimize.
Type: object
Type: Array
Plugins to use.