What is @parcel/optimizer-svgo?
@parcel/optimizer-svgo is a Parcel plugin that optimizes SVG files using SVGO (SVG Optimizer). It helps reduce the size of SVG files by removing unnecessary data and optimizing the SVG structure, which can improve load times and performance for web applications.
Basic SVG Optimization
This feature allows you to optimize a basic SVG string using the @parcel/optimizer-svgo package. The optimizer removes unnecessary data and optimizes the SVG structure.
const { Optimizer } = require('@parcel/optimizer-svgo');
const optimizer = new Optimizer();
const svg = '<svg>...</svg>';
const optimizedSvg = optimizer.optimize(svg);
console.log(optimizedSvg);
Custom SVGO Configuration
This feature allows you to customize the SVGO configuration by specifying which plugins to use and their settings. This provides more control over the optimization process.
const { Optimizer } = require('@parcel/optimizer-svgo');
const optimizer = new Optimizer({
plugins: [
{ name: 'removeDoctype', active: true },
{ name: 'removeComments', active: true }
]
});
const svg = '<svg>...</svg>';
const optimizedSvg = optimizer.optimize(svg);
console.log(optimizedSvg);