What is imagemin-svgo?
The imagemin-svgo npm package is a plugin for Imagemin that uses SVGO (SVG Optimizer) to compress and optimize SVG files. It helps reduce the file size of SVG images by removing unnecessary data without affecting the visual quality.
What are imagemin-svgo's main functionalities?
Basic SVG Optimization
This code demonstrates how to use imagemin-svgo to optimize SVG files in the 'images' directory and save the optimized files to the 'output/images' directory.
const imagemin = require('imagemin');
const imageminSvgo = require('imagemin-svgo');
(async () => {
await imagemin(['images/*.svg'], {
destination: 'output/images',
plugins: [
imageminSvgo()
]
});
console.log('SVG images optimized');
})();
Custom SVGO Options
This code shows how to use imagemin-svgo with custom SVGO options. In this example, the 'removeViewBox' and 'cleanupIDs' plugins are configured to preserve the viewBox attribute and IDs in the SVG files.
const imagemin = require('imagemin');
const imageminSvgo = require('imagemin-svgo');
(async () => {
await imagemin(['images/*.svg'], {
destination: 'output/images',
plugins: [
imageminSvgo({
plugins: [
{ removeViewBox: false },
{ cleanupIDs: false }
]
})
]
});
console.log('SVG images optimized with custom options');
})();
Other packages similar to imagemin-svgo
svgo
SVGO (SVG Optimizer) is a standalone tool for optimizing SVG files. It provides a command-line interface and can be used as a library in Node.js applications. While imagemin-svgo is a plugin for Imagemin, svgo can be used independently for more direct control over SVG optimization.
svgmin
svgmin is another tool for optimizing SVG files. It is similar to svgo but offers different optimization strategies and configurations. svgmin can be used as a command-line tool or integrated into build processes. It provides an alternative to imagemin-svgo with its own set of features and options.
imagemin-svgo
svgo image-min plugin
Install
$ npm install --save imagemin-svgo
Usage
var Imagemin = require('image-min');
var svgo = require('imagemin-svgo');
var imagemin = new Imagemin()
.src('foo.svg')
.dest('foo-optimized.svg')
.use(svgo());
imagemin.optimize();
Options
plugins
Type: Array
Default: []
Customize which SVGO plugins to use.
var imagemin = new Imagemin()
.use(svgo({ plugins: [{ removeViewBox: false, removeEmptyAttrs: false }] }));
License
MIT © imagemin