svgo
Optimize SVG vector graphics files
TLDR
Optimize a file using the default plugins (overwrites the original file)
Optimize a file and save the result to another file
Optimize all SVG files within a directory (overwrites the original files)
Optimize all SVG files within a directory and save the resulting files to another directory
Optimize SVG content passed from another command, and save the result to a file
Optimize a file and print out the result
Show available plugins
SYNOPSIS
svgo [options] [<input_path>] [<output_path>]
svgo --input <file> --output <file>
svgo --folder <folder> --output <folder>
svgo --config <path_to_config_file>
PARAMETERS
-i, --input <path>
Specifies the input SVG file or folder for optimization. Use '-' for standard input.
-o, --output <path>
Specifies the output path for the optimized SVG file or folder. Use '-' for standard output.
-f, --folder <path>
Processes all SVG files within the specified input folder, outputting to the corresponding folder.
-p, --pretty
Formats the output SVG with human-readable indentation, making it easier to read.
-t, --multipass
Runs the optimization process multiple times until the SVG no longer changes, potentially achieving better compression.
-c, --config <file>
Specifies a custom configuration file (e.g., svgo.config.js) to control plugins and optimization settings.
--dataurl <encoding>
Outputs the optimized SVG as a data URL, with optional encoding like 'base64' or 'utf8'.
--enable-plugin <name>
Enables a specific optimization plugin by its name. Can be used multiple times to enable several plugins.
--disable-plugin <name>
Disables a specific optimization plugin by its name. Can be used multiple times to disable several plugins.
-q, --quiet
Suppresses most informational output, showing only critical errors.
-v, --version
Displays the installed svgo version number.
-h, --help
Displays the command-line help message with available options and usage examples.
DESCRIPTION
SVGO (SVG Optimizer) is a powerful, Node.js-based tool designed to significantly reduce the file size of SVG (Scalable Vector Graphics) images. It achieves this by intelligently identifying and removing various types of redundant and useless information embedded within SVG files. This includes eliminating editor metadata, comments, hidden elements, default values for attributes, empty groups, and unreferenced IDs. The optimization process results in smaller SVG files, which translates to faster loading times on websites, improved rendering performance in applications, and more efficient storage. SVGO is highly configurable, offering a robust plugin-based architecture that allows users to precisely control which optimizations are applied, making it adaptable for a wide range of use cases, from web development and icon processing to graphic design workflows.
CAVEATS
svgo requires Node.js to be installed on the system to run. While highly effective, aggressive optimization settings or issues in the original SVG markup can, in rare cases, lead to minor rendering inconsistencies. Users should test optimized SVGs in their target environments.
CONFIGURATION FILES
svgo's behavior is extensively customizable through configuration files, typically named svgo.config.js. These files allow users to define which built-in plugins are active, configure their specific parameters, and even register custom plugins. This provides fine-grained control over the optimization process, tailoring it to specific project requirements.
PLUGIN SYSTEM
The core of svgo's functionality lies in its modular plugin system. Each plugin is responsible for a distinct optimization task, such as removing comments, converting shapes to paths, or collapsing redundant groups. This modularity ensures that users can selectively apply or disable optimizations, ensuring compatibility and desired output quality without sacrificing performance.
HISTORY
svgo was initially developed by Kirill K. and first released around 2013, quickly gaining traction as a vital tool for web optimization. It transitioned to a community-maintained project under the svg/svgo organization. A significant update, v2.0.0, introduced a new plugin API and a shift from YAML to JavaScript-based configuration files, enhancing its flexibility and extensibility.