imagemin
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
file-type | 16.5.4 | 20.42 kB | MIT | prod | |
globby | 12.2.0 | 6.47 kB | MIT | prod | |
graceful-fs | 4.2.11 | 9.57 kB | ISC | prod | |
junk | 3.1.0 | 2.28 kB | MIT | prod | |
p-pipe | 4.0.0 | 2.43 kB | MIT | prod | |
replace-ext | 2.0.0 | 2.4 kB | MIT | prod | |
slash | 3.0.0 | 1.8 kB | MIT | prod |
Imagemin is a powerful npm tool designed to seamlessly minify images. It works by reducing the file size of your images without affecting their quality, making your websites load faster and use less bandwidth. This streamlined performance can also enhance UX, helping to improve your site's SEO.
Imagemin is incredibly simple to use. To get started, first install the tool via npm, using the command npm install imagemin
. Once installed, a typical usage would look like this:
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: <Buffer 89 50 4e β¦>, destinationPath: 'build/images/foo.jpg'}, β¦]
In the example above, the imagemin
function takes in an array of file paths or glob patterns of the images to be minified, pointing to their locations on your file system. The function then optimizes these images using different plugins (in this case, imageminJpegtran
and imageminPngquant
). The resulting minified images are stored in the specified destination folder (build/images
).
The documentation for imagemin can be found on its GitHub page or within the readme file in the package. This includes the API, different usages, and related tools. Potential plugins to use with imagemin can be found on npm under the keyword imageminplugin. Be sure to look through these resources for detailed guidance on how to use and customize the tool for your specific needs.