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 imagemin plugin
Install
$ npm install --save imagemin-svgo
Usage
const Imagemin = require('imagemin');
const imageminSvgo = require('imagemin-svgo');
new Imagemin()
.src('images/*.svg')
.dest('build/images')
.use(imageminSvgo())
.run();
You can also use this plugin with gulp:
const gulp = require('gulp');
const imageminSvgo = require('imagemin-svgo');
gulp.task('default', () => {
return gulp.src('images/*.svg')
.pipe(imageminSvgo()())
.pipe(gulp.dest('build/images'));
});
API
imageminSvgo(options)
options
Type: object
Pass options to svgo.
License
MIT © imagemin