NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm · #1380 most downloaded on npm
SVGO is a Node.js library and command-line application for optimizing vector images.
Last release 1 months ago
24 Aug 2026
Release timing varies
gaps range from 1 weeks to 8 months
Nearly every release is documented
notes for 35 of 35 stable releases
84 versions withdrawn
withdrawn after publishing
14 years old
119 releases · first in 2012
This minor release upgrades the SAX parser and introduces stricter XML validation. It also includes important security hardening for removeScripts , d
This minor release upgrades the SAX parser and introduces stricter XML validation. It also includes important security hardening for removeScripts, dependency updates, and improvements to the test and regression infrastructure.
If SVGO is valuable to you or your organization, please consider supporting the project on OpenCollective. Your sponsorship helps fund ongoing maintenance and security work.
SVGO now uses sax 1.6.1, upgraded from 1.5.0 (#2257).
The new parser version validates numeric character references against the ranges permitted by XML. Invalid references are now rejected in both text and attributes, including:
, , and ;�;.Valid boundary values—including U+0020, U+D7FF, U+E000, U+FFFD, and characters through U+10FFFF—remain supported.
Parser failures are consistently exposed as SvgoParserError errors with an Invalid character entity reason.
This is an intentional behavior change: malformed SVGs that were previously accepted may now produce a parser error, while valid XML documents are unaffected.
The removeScripts plugin has been hardened against several script-execution bypasses:
data: URLs containing HTML, XHTML, or SVG documents while preserving inert data such as PNG images, and filters legacy vbscript: URLs (#2263).<foreignObject> elements by removing HTML event-handler attributes, srcdoc, and executable URLs from action, data, formaction, href, and src, while preserving non-executable HTML and visual content (#2264).<a> elements and removes ASCII tabs and newlines before checking URL schemes, preventing values such as java	script: from bypassing detection while preserving elements in unrelated custom namespaces (#2268).These changes address:
css-select to v6 and css-what to v7, and updated SVGO's custom selector adapter for css-select v6 (#2244).@TrySound is back as an active SVGO maintainer.
Many thanks to @KTibow, @SethFalco, and @XhmikosR for maintaining and improving SVGO over the past several years.
Full Changelog: v4.0.2...v4.1.0
One column per quarter.
removeScripts , remove JavaScript URIs case-insensitively and make <script> handling namespace aware. By @SethFalco
<script> handling namespace aware. By @SethFalcot commands. By @KTibow in #2156Sets minimum version of sax (XML parser) to v1.5.0, which improves built-in guards against entity expansion.
<use> elements referencing an empty container that were removed. By @johnkenny54 in #2051--show-plugins argument appends the presets a plugin is in to the end of the line. By @viralcodex in #2174preset- if it is a preset (collection of plugins). By @SethFalco in #2178Before and after of the browser bundle of each respective version:
| v4.0.0 | v4.0.1 | Delta | |
|---|---|---|---|
| svgo.browser.js | 780.2 kB | 781.5 kB | ⬆️ 1.3 kB |
removeDeprecatedAttrs, new plugin that is disabled by default to remove SVG attributes that are deprecated. By @jdufresne in #1869
<div align="center">
Illustration by Vukory
</div>
It's been just over a year since our first release candidate, but I believe we can now release SVGO v4.0.0 with confidence! Thank you to all contributors who tested our RC builds and reported issues back up, this really smoothed out the process.
We actually wanted to do the release sooner, but it was a challenge to find the right time to publish a major release, since that means setting time aside to support users through migrations, helping downstream projects migrate, being available to fix or document things that users found to have an unexpected impact by this release, etc. I appreciate everyone's patience, and now that this is done, we can hopefully increase the pace of development again and tackle that backlog of old bugs. ^-^'
Please refer to the Migration Guide from v3 to v4 for a more concise version! This section is more verbose as it delves into the motivation of changes too.
Node.js v14 is no longer supported by the Node.js team, including security support, since 30 April 2023. Node.js v16 is no longer supported either, but as some are still using it, we'll save dropping support for Node.js v16 for the next major release.
This allows us to update our dependencies to more recent versions and to access more modern Node.js APIs.
Node.js v14 may still work at the time of this release, but we'll no longer be testing against v14 from now on.
Both removeViewBox and removeTitle have been disabled by default. Both have been major pain points for users and don't make sense to enable in most cases. Other libraries wrapping SVGO have also been disabling these plugins by default, such as Docusaurus and SVGR.
If you would like either of these plugins enabled, you can do so by configuring it in the SVGO config, see the README for more context, however please read the warnings described in the documentation of the plugins first:
export default {
plugins: [
'preset-default', // built-in plugins enabled by default
+ 'removeViewBox',
+ 'removeTitle',
],
};
The removeScriptElement plugin has been renamed to removeScripts, to more accurately reflect what the plugin does. It does not only remove the <script> tag, but also event handlers and script URIs from links.
To migrate, amend your SVGO config to refer to removeScripts instead if you use that plugin.
export default {
plugins: [
'preset-default', // built-in plugins enabled by default
- 'removeScriptElement',
+ 'removeScripts',
],
};
We now enforce boundaries between the intended public API and any internal structures/helpers. This is the biggest change in SVGO's JavaScript API and will enable maintainers and users to have a mutual understanding of what is public API and what isn't.
There are two ways to import SVGO:
svgo — for normal usage, such as scripts or server-side applications.svgo/browser — for browser usage.If you use the browser bundle, you must amend how you import SVGO:
- import { optimize } from 'svgo/dist/svgo.browser.js';
+ import { optimize } from 'svgo/browser';
For ESM/browser, you must use named imports:
// ESM and Browser, named exports
import { VERSION } from 'svgo';
console.log(VERSION); // 4.0.0-rc.0
// ESM and Browser, import all
import * as svgo from 'svgo/browser';
console.log(svgo.VERSION); // 4.0.0-rc.0
// Common JS, default export
const svgo = require('svgo');
console.log(svgo.VERSION); // 4.0.0-rc.0
// CommonJS, named exports
const { VERSION } = require('svgo');
console.log(VERSION); // 4.0.0-rc.0
We support 3 environments, ESM, Common JS, and browser. The only functional difference is that the loadConfig function is not exported in the browser bundle.
If you depended on a helper that we haven't declared as public, then you are encouraged to implement it yourself, or dig into our source and copy it over to your project.
If you import/require the array of built-in plugins, or a single plugin during runtime, this is now a top-level export instead:
// builtin.mjs - get an array of all built-in plugins
- import { builtin } from 'svgo/lib/builtin';
+ import { builtinPlugins } from 'svgo'
// plugin.mjs - get a single plugin
- import presetDefault from 'svgo/plugins/preset-default';
+ import { builtinPlugins } from 'svgo';
+ const presetDefault = builtinPlugins.find(plugin => plugin.name === 'preset-default');
// plugin-map.mjs - get all plugins as a map using the plugin name as a key
import { builtinPlugins } from 'svgo';
const pluginMap = builtinPlugins.reduce((acc, val) => acc.set(val.name, val), new Map());
The XastNode#parentNode property was declared legacy and pending removal for v4, but was still used internally. The remaining instances have now been removed, which required a refactor of the selector helpers.
This effects custom plugins that use any of the following functions, where the selector (2nd) argument could reference parent or sibling nodes (i.e. div > span):
querySelectorAllquerySelectormatchesPreviously, these functions had the context of the whole node tree, even if a child node was passed to it. It no longer has that context by default. The new API for these functions is as follows:
// applies `selector` with the context of the `childNode` and its descendants
const nodes = querySelectorAll(childNode, selector);
// applies `selector` with the context of the entire node tree relative from `childNode`
// the `rootNode` is required if the result of `selector` may depend on the parent or sibling of `childNode`
const nodes = querySelectorAll(childNode, selector, rootNode);
// this usage has the same behavior as v3, as `rootNode` is already the entire node tree
const nodes = querySelectorAll(rootNode, selector);
A helper has been provided named #mapNodesToParents, which does this for you. This can be used to easily migrate to the new API. If you're not sure if you need it, then it's safer to take this approach. The third argument won't be necessary if selector does not traverse nodes, for example, querying using one or more attributes of a single node.
- import { querySelectorAll } from 'svgo';
+ import { querySelectorAll, mapNodesToParents } from 'svgo';
- const nodes = querySelectorAll(childNode, selector);
+ const nodes = querySelectorAll(childNode, selector, mapNodesToParents(rootNode));
SVGO is now a dual package, serving for both Common JS and ESM usage. To be more explicit, SVGO will continue to work on Common JS projects!
Thanks to @jdufresne for doing the bulk of the work.
convertCase to false.filter attribute. By @johnkenny54 in #1933path[opacity=0] as a non-rendering node. By @johnkenny54 in #1948-o argument) ends with a trailing slash to a location that didn't exist. By @SethFalco in #1954VERSION export so get the version of SVGO during runtime. By @SethFalco in #2016isPreset and plugins property to plugins, which are only defined for presets. This will indicate if the plugin is a preset, and return the plugins that are in the preset in the order they are invoked.Before and after using vectors from various sources, with the default preset of each respective version:
| SVG | Original | v3.3.2 | v4.0.0 | Delta |
|---|---|---|---|---|
| Arch Linux Logo | 9.529 KiB | 4.115 KiB | 4.097 KiB | ⬇️ 0.018 KiB |
| Blobs | 50.45 KiB | 42.623 KiB | 42.633 KiB | ⬆️ 0.01 KiB |
| Isometric Madness | 869.034 KiB | 540.582 KiB | 540.141 KiB | ⬇️ 0.441 KiB |
| tldr-pages Banner | 2.071 KiB | 1.07 KiB | 1.07 KiB | |
| Wikipedia Logo | 161.551 KiB | 111.668 KiB | 111.727 KiB | ⬆️ 0.059 KiB |
Note: The increase in size from previous versions is from disabling removeViewBox and removeTitle, with the benefit of preserving scalability and accessibility.
Before and after of the browser bundle of each respective version:
| v3.3.2 | v4.0.0 | Delta | |
|---|---|---|---|
| svgo.browser.js | 753.0 kB | 780.2 kB | ⬆️ 27.2 kB |
The migration guide is more concise than the release notes, and only covers the breaking changes.
This is a release candidate. We are still working on v4.0.0, and API stability isn't guaranteed, though we'll aim to keep it fairly consistent. You can try this build by installing or depending on svgo@4.0.0-rc.5, or svgo@rc.
Please report any problems you encounter in the GitHub issue tracker. :+1:
Refer to the release notes of previous v4.0.0 release candidates to get the full context, this will only describe the differences since the previous release candidate.
We're also working on a Migration Guide from v3 to v4. This will be accessible on svgo.dev once SVGO v4 has been officially released, but currently can only be read from the repository. The migration guide is more concise than the release notes, and only covers the breaking changes.
currentColor instead of currentcolor by @SethFalco in https://github.com/svg/svgo/pull/2137Thanks, @futuremotiondev and @Studio384, who reported the issues. :+1:
No functional changes have been made that would affect SVG optimization or the browser bundle.
The migration guide is more concise than the release notes, and only covers the breaking changes.
This is a release candidate. We are still working on v4.0.0, and API stability isn't guaranteed, though we'll aim to keep it fairly consistent. You can try this build by installing or depending on svgo@4.0.0-rc.4, or svgo@rc.
Please report any problems you encounter in the GitHub issue tracker. :+1:
Refer to the release notes of previous v4.0.0 release candidates to get the full context, this will only describe the differences since the previous release candidate.
We're also working on a Migration Guide from v3 to v4. This will be accessible on svgo.dev once SVGO v4 has been officially released, but currently can only be read from the repository. The migration guide is more concise than the release notes, and only covers the breaking changes.
Fixes the type declarations for #loadConfig, which were incorrect in v4.0.0-rc.2 and didn't perfectly match previous releases. The types should now behave the same as v3, and we've added stricter tests to enforce this with tsd.
expectType<Promise<Config | null>>(loadConfig());
expectType<Promise<Config | null>>(loadConfig(undefined));
expectType<Promise<Config | null>>(loadConfig(null));
expectType<Promise<Config>>(loadConfig('svgo.config.js'));
Thanks, @ntnyq, who reported this issue and contributed a fix.
No functional changes have been made that would affect SVG optimization or the browser bundle.
SVGO v4.0.0-rc.3 was accidentally published as a stable release instead of a release candidate. I noticed this within minutes, deprecated that version, and re-assigned the latest dist tag to v3.3.2. Fortunately, the impact should be minimal as most projects pin to major versions, which ^3 does not overlap with v4.0.0-rc.3.
I'm very sorry for any inconvenience this may have caused, though. :bow:
I will discuss this with the other maintainers, to see if I can get the permissions necessary on GitHub to migrate our publishing workflow to GitHub Actions. That should reduce the risk of this from happening again.
Nothing published for this version
The migration guide is more concise than the release notes, and only covers the breaking changes.
I apologize for the wait, and I appreciate everyone's patience! It's been some time since the last release candidate as I was very busy with client work. ^-^'
This is a release candidate. We are still working on v4.0.0, and API stability isn't guaranteed, though we'll aim to keep it fairly consistent. You can try this build by installing or depending on svgo@4.0.0-rc.2, or svgo@rc.
Please report any problems you encounter in the GitHub issue tracker. :+1:
Refer to the release notes of previous v4.0.0 release candidates to get the full context, this will only describe the differences since the previous release candidate.
We're also working on a Migration Guide from v3 to v4. This will be accessible on svgo.dev once SVGO v4 has been officially released, but currently can only be read from the repository. The migration guide is more concise than the release notes, and only covers the breaking changes.
This release mostly sets out to resolve issues reported regarding v4.0.0-rc.1. There was a mistake with our type declarations, that led to named exports like optimize to not be handled correctly.
I've amended the project to move away from manually maintained type declaration files, to generating our type declarations using tsc based on our JSDoc types and local types. This should guarantee that our type declarations will be up-to-date with our implementation from now on.
This release drops default exports from the library. My original plan was to keep them in SVGO v4, and export with both named and default exports. However, this seems a little more annoying to maintain than I was expecting.
If you are using the import syntax and imported SVGO via the default export, then you must adapt your code for v4:
- import svgo from 'svgo';
- svgo.optimize('<svg></svg>');
// Option 1. Use named exports!
+ import { optimize } from 'svgo';
+ optimize('<svg></svg>');
// Option 2. Or import everything as svgo!
+ import * as svgo from 'svgo';
+ svgo.optimize('<svg></svg>');
This has no impact on users who:
require).If you'd like more details on the reason, please see: https://github.com/svg/svgo/pull/2118
The XastNode#parentNode property was declared legacy and pending removal for v4, but was still used internally. The remaining instances have now been removed, which required a refactor of the selector helpers.
This effects custom plugins that use any of the following functions, where the selector (2nd) argument could reference parent or sibling nodes (i.e. div > span):
querySelectorAllquerySelectormatchesPreviously, these functions had the context of the whole node tree, even if a child node was passed to it. It no longer has that context by default. The new API for these functions are as follows:
// applies `selector` with the context of the `childNode` and its descendants
const nodes = querySelectorAll(childNode, selector);
// applies `selector` with the context of the entire node tree relative from `childNode`
// the `rootNode` is required if the result of `selector` may depend on the parent or sibling of `childNode`
const nodes = querySelectorAll(childNode, selector, rootNode);
// this usage has the same behavior as v3, as `rootNode` is already the entire node tree
const nodes = querySelectorAll(rootNode, selector);
A helper has been provided named #mapNodesToParents, which does this for you. This can be used to easily migrate to the new API. If you're not sure if you need it, then it's safer to take this approach. The third argument won't be necessary if selector does not traverse nodes, for example querying using one or more attributes of a single node.
- import { querySelectorAll } from 'svgo';
+ import { querySelectorAll, mapNodesToParents } from 'svgo';
- const nodes = querySelectorAll(childNode, selector);
+ const nodes = querySelectorAll(childNode, selector, mapNodesToParents(rootNode));
No functional changes have been made that would affect SVG optimization.
Before and after of the browser bundle of each respective version:
| v4.0.0-rc.0 | v4.0.0-rc.2 | Delta | |
|---|---|---|---|
| svgo.browser.js | 754.9 kB | 780.1 kB | ⬆️ 25.2 kB |
This is a release candidate. We are still working on v4.0.0, and API stability isn't guaranteed, though we'll aim to keep it fairly consistent. You ca
This is a release candidate. We are still working on v4.0.0, and API stability isn't guaranteed, though we'll aim to keep it fairly consistent. You can try this build by installing or depending on svgo@4.0.0-rc.1, or svgo@rc.
Please report any problems you encounter in the GitHub issue tracker. :+1:
Refer to the release notes of previous v4.0.0 release candidates to get the full context, this will only describe the differences since the previous release candidate.
We now enforce a public API, however we received feedback from users who make custom plugins that they depended on some of our other types and helpers.
The types (XastNode, etc.) should've been exported, which has now been resolved.
Some of our functions like querySelector and querySelectorAll were not actually intended to be part of our public API. As our README.md suggests, the API usage primarily entails optimize and loadConfig. However, there are valid use cases for this, so we'll export the ones that are frequently used and continue and ensure backward compatibility to make plugin development easier, and for ease of migration between v3 and v4.
This means users that develop custom plugins will have stronger API guarantees when using querySelector, querySelectorAll, and _collections. However, they should be imported from svgo or svgo/browser now.
- import { querySelector, querySelectorAll } from 'svgo/lib/xast.js';
+ import { querySelector, querySelectorAll } from 'svgo';
- import _collections from 'svgo/plugins/_collections';
+ import { _collections } from 'svgo';
// For TypeScript users!
- import type { XastElement, XastRoot, XastChild } from 'svgo/lib/types';
+ import type { XastElement, XastRoot, XastChild } from 'svgo';
removeDeprecatedAttrs, new plugin that is disabled by default to remove SVG attributes that are deprecated. By @jdufresne in #1869
This is a release candidate. We are still working on v4.0.0, and API stability isn't guaranteed, though we'll aim to keep it fairly consistent. You can try this build by installing or depending on svgo@4.0.0-rc.0, or svgo@rc.
Please report any problems you encounter in the GitHub issue tracker. 👍🏽
A summary, if you use the browser bundle of SVGO, or import/require anything except the base svgo path, such as svgo/lib/builtin, then you will very likely have to make code changes to update to version 4.
Node.js v14 is no longer supported by the Node.js team, including security support since 30 April 2023. Node.js v16 is no longer supported either, but as many are still using it, we'll continue to support Node.js v16 for now.
This allows us to update our dependencies to more recent versions, and to access more modern Node.js APIs.
Node.js v14 may still work at the time of this release, but we'll no longer be testing against v14 from now on.
We now enforce boundaries between the intended public API and any internal structures/helpers.
There are two ways to import SVGO:
svgo — for normal usage, such as scripts or server-side applications.svgo/browser — for browser usage.If you use the browser bundle, you must amend how you import SVGO:
- import { optimize } from 'svgo/dist/svgo.browser.js';
+ import { optimize } from 'svgo/browser';
For all interfaces, it's recommended to use our named exports:
// ESM and Browser, named exports
import { VERSION } from 'svgo';
console.log(VERSION); // 4.0.0-rc.0
// ESM and Browser, import all
import * as svgo from 'svgo/browser';
console.log(svgo.VERSION); // 4.0.0-rc.0
// Common JS, default export
const SVGO = require('svgo');
console.log(SVGO.VERSION); // 4.0.0-rc.0
// CommonJS, named exports
const { VERSION } = require('svgo');
console.log(VERSION); // 4.0.0-rc.0
We support 3 environments, ESM, Common JS, and browser. The only functional difference is that the loadConfig function is not exported in the browser bundle.
If you import/require the array of built-in plugins, or a single plugin during runtime, this is now a top-level export instead:
// builtin.mjs - get an array of all built-in plugins
- import { builtin } from 'svgo/lib/builtin';
+ import { builtinPlugins } from 'svgo'
// plugin.mjs - get a single plugin
- import presetDefault from 'svgo/plugins/preset-default';
+ import { builtinPlugins } from 'svgo';
+ const presetDefault = builtinPlugins.find(plugin => plugin.name === 'preset-default');
// plugin-map.mjs - get all plugins as a map using the plugin name as a key
import { builtinPlugins } from 'svgo';
const pluginMap = builtinPlugins.reduce((acc, val) => acc.set(val.name, val), new Map());
Both removeViewBox and removeTitle have been disabled by default. Both have been major pain points for users, and don't make sense to enable in most cases. Other libraries wrapping SVGO have also been disabling these plugins by default, such as Docusaurus and SVGR.
If you would like either of these plugins enabled, you can do so by configuring it in the SVGO config, see the README for more context:
export default {
plugins: [
'preset-default', // built-in plugins enabled by default
+ 'removeViewBox',
+ 'removeTitle',
],
};
The removeScriptElement plugin has been renamed to removeScripts, to more accurately reflect what the plugin does. It does not only remove the <script> tag, but also event handlers and script URIs from links.
To migrate, amend your SVGO config to refer to removeScripts instead if you use that plugin.
export default {
plugins: [
'preset-default', // built-in plugins enabled by default
- 'removeScriptElement',
+ 'removeScripts',
],
};
SVGO is now a dual package, serving for both Common JS and ESM usage. To be more explicit, SVGO will continue to work in Common JS projects!
Thanks to @jdufresne for doing the bulk of the work.
convertCase to false.filter attribute. By @johnkenny54 in #1933path[opacity=0] as a non-rendering node. By @johnkenny54 in #1948-o argument) ends with a trailing slash to a location that didn't exist. By @SethFalco in #1954VERSION export so get the version of SVGO during runtime. By @SethFalco in #2016isPreset and plugins property to plugins, which are only defined for presets. This will indicate if the plugin is a preset, and return the plugins that in the preset in the order they are invoked.Before and after using vectors from various sources, with the default preset of each respective version:
| SVG | Original | v3.3.2 | v4.0.0-rc.0 | Delta |
|---|---|---|---|---|
| Arch Linux Logo | 9.529 KiB | 4.115 KiB | 4.097 KiB | ⬇️ 0.018 KiB |
| Blobs | 50.45 KiB | 42.623 KiB | 42.633 KiB | ⬆️ 0.01 KiB |
| Isometric Madness | 869.034 KiB | 540.582 KiB | 540.141 KiB | ⬇️ 0.441 KiB |
| tldr-pages Banner | 2.071 KiB | 1.07 KiB | 1.07 KiB | |
| Wikipedia Logo | 161.551 KiB | 111.668 KiB | 111.727 KiB | ⬆️ 0.059 KiB |
Note: The increase in size from previous versions is from disabling removeViewBox and removeTitle, with the benefit of preserving scalability and accessibility.
Before and after of the browser bundle of each respective version:
| v3.3.2 | v4.0.0-rc.0 | Delta | |
|---|---|---|---|
| svgo.browser.js | 753.0 kB | 754.9 kB | ⬆️ 1.9 kB |
SVGO v3 is not officially supported; please consider upgrading to SVGO v4. This security fix has been backported, but there is no commitment to backpo…
removeScriptElement hardening from SVGO v4 in #2269:
data: URLs and legacy vbscript: URLs<foreignObject> elementsThis addresses GHSA-4vpr-x523-8j87 and GHSA-w27v-7q3p-w38r for the v3 release line.
SVGO v3 is not officially supported; please consider upgrading to SVGO v4. This security fix has been backported, but there is no commitment to backport more complex changes in the future.
See the migration guide from v3 to v4.
removeScriptElement , remove JavaScript URIs case-insensitively and make <script> handling namespace aware. By @SethFalco
<script> handling namespace aware. By @SethFalcoSVGO v3 is not officially supported, please consider upgrading to SVGO v4 instead. We've backported this fix as there are security implications, but there is no commitment to do this for more complex changes in future.
Consider reading our Migration Guide from v3 to v4 which should ease the process.
Migrates from our unsupported fork of sax ( @trysound/sax ) to the upstream version of sax ( sax ).
Before and after of the browser bundle of each respective version:
| v3.3.2 | v3.3.3 | Delta | |
|---|---|---|---|
| svgo.browser.js | 910.9 kB | 912.9 kB | ⬆️ 2 kB |
SVGO v3 is not officially supported, please consider upgrading to SVGO v4 instead. We've backported this fix as there are security implications, but there is no commitment to do this for more complex changes in future.
Consider reading our Migration Guide from v3 to v4 which should ease the process.
This effectively made SVGO v3 a breaking change.
An update on what happened with v3.3.0 and v3.3.1. While we have retained CJS support, the migration to ESM has changed the acceptable ways to import SVGO, in ways that users depended on before. This effectively made SVGO v3 a breaking change.
Rather than resolve or workaround these differences, we've opted to release SVGO v3.3.2, which is effectively a revert to v3.2.0, and deprecate versions v3.3.0 and v3.3.1. We'll then proceed to work on releasing v4 which will document the breaking changes, and feature further breaking changes that were slated for v4, like disabling removeViewBox by default.
Before the v4.0.0 release, I'll put more focus on testing and use release candidates, just to make the release go smoothly! 👍🏽
Sorry for the headache, and thank you for your patience.
I apologize for letting that breaking change through, and will aim to do better. Namely, by adding more tests to cover our exports, and any other publ…
SVGO v3.3.0, which was meant to migrate to ESM without breaking CJS support, unfortunately broke CJS projects. There was a mistake with exports, so the loadConfig function wasn't available in the CJS bundle and lead to issues for many users.
Thanks to everyone who raised the issue, and to @nuintun who submitted a pull request to resolve it so quickly.
I apologize for letting that breaking change through, and will aim to do better. Namely, by adding more tests to cover our exports, and any other public interface in general for each distribution of SVGO, so this doesn't happen again.
SVGO v3.3.1 should resolve the issue for CJS projects, but if you encounter anything else, do let us know by opening an issue on GitHub.
This release introduced breaking changes, which have been reverted in v3.3.2. The bug fixes will be reintroduced in v4.0.0.
This release introduced breaking changes, which have been reverted in v3.3.2. The bug fixes will be reintroduced in v4.0.0.
SVGO is now a dual package, serving for both Common JS and ESM usage. We believe there shouldn't be any problems, especially as SVGO as largely stateless, but feel free to open an issue if you encounter problems with this.
To be explicit, this is not a breaking change, and SVGO should continue to work in Common JS projects!
Thanks to @jdufresne for doing the bulk of the work.
convertCase to false.filter attribute. By @johnkenny54 in #1933path[opacity=0] as a non-rendering node. By @johnkenny54 in #1948-o argument) ends with a trailing slash to a location that didn't exist. By @SethFalco in #1954Before and after using vectors from various sources, with the default preset of each respective version:
| SVG | Original | v3.2.0 | v3.3.0 | Delta |
|---|---|---|---|---|
| Arch Linux Logo | 9.529 KiB | 4.115 KiB | 4.097 KiB | ⬇️ 0.018 KiB |
| Blobs | 50.45 KiB | 42.623 KiB | 42.609 KiB | ⬇️ 0.014 KiB |
| Isometric Madness | 869.034 KiB | 540.582 KiB | 540.073 KiB | ⬇️ 0.509 KiB |
| tldr-pages Banner | 2.071 KiB | 1.07 KiB | 1.07 KiB | |
| Wikipedia Logo | 161.551 KiB | 111.668 KiB | 111.668 KiB |
Before and after of the browser bundle of each respective version:
| v3.2.0 | v3.3.0 | Delta | |
|---|---|---|---|
| svgo.browser.js | 910.9 kB | 753.0 kB | ⬇️ 157.9 kB |
convertPathData, fix instances were q was incorrectly converted to t. By @KTibow in https://github.com/svg/svgo/pull/1889
q was incorrectly converted to t. By @KTibow in https://github.com/svg/svgo/pull/1889smartArcRounding to false. By @KTibow in https://github.com/svg/svgo/pull/1873convertToQ to false. By @KTibow in https://github.com/svg/svgo/pull/1889#stringifyPathData for performance. By @SethFalco in https://github.com/svg/svgo/pull/1900Set instead of Array for faster lookups. By @SethFalco in https://github.com/svg/svgo/pull/1899Before and after using vectors from various sources, with the default preset of each respective version:
| SVG | Original | v3.1.0 | v3.2.0 | Delta |
|---|---|---|---|---|
| Arch Linux Logo | 9.529 KiB | 4.162 KiB | 4.115 KiB | ⬇️ 0.047 KiB |
| Blobs | 50.45 KiB | 42.949 KiB | 42.623 KiB | ⬇️ 0.326 KiB |
| Isometric Madness | 869.034 KiB | 550.153 KiB | 540.582 KiB | ⬇️ 9.571 KiB |
| tldr-pages Banner | 2.071 KiB | 1.07 KiB | 1.07 KiB | |
| Wikipedia Logo | 161.551 KiB | 116 KiB | 111.668 KiB | ⬇️ 4.332 KiB |
Before and after of the browser bundle of each respective version:
| v3.1.0 | v3.2.0 | Delta | |
|---|---|---|---|
| svgo.browser.js | 660.9 kB | 910.9 kB | ⬆️ 250 kB |
prefixIds, correctly prefix IDs when tag contains XML comments. By @john-neptune in https://github.com/svg/svgo/pull/1736
<style> tag contains XML comments. By @john-neptune in https://github.com/svg/svgo/pull/1736<defs>), namely when <defs> are defined at the end of the document. By @KTibow in https://github.com/svg/svgo/pull/1879url('#a')) across various plugins. By @SethFalco in https://github.com/svg/svgo/pull/1881defaultMarkupDeclarations. By @SethFalco in https://github.com/svg/svgo/pull/1872Before and after using vectors from various sources, with the default preset of each respective version:
| SVG | Original | v3.0.5 | v3.1.0 | Delta |
|---|---|---|---|---|
| Arch Linux Logo | 9.529 KiB | 4.608 KiB | 4.162 KiB | ⬇️ 0.446 KiB |
| Blobs | 50.45 KiB | 42.949 KiB | 42.949 KiB | |
| Isometric Madness | 869.034 KiB | 550.153 KiB | 550.153 KiB | |
| tldr-pages Banner | 2.071 KiB | 1.07 KiB | 1.07 KiB | |
| Wikipedia Logo | 161.551 KiB | 117.146 KiB | 116 KiB | ⬇️ 1.146 KiB |
Before and after of the browser bundle of each respective version:
| v3.0.5 | v3.1.0 | Delta | |
|---|---|---|---|
| svgo.browser.js | 657.5 kB | 660.9 kB | ⬆️ 3.4 kB |
cleanupIds, correctly handle references to other nodes in animations. By @KTibow in https://github.com/svg/svgo/pull/1862
Z between mergable M/m commands. By @KTibow in https://github.com/svg/svgo/pull/1856z conversions. By @KTibow in https://github.com/svg/svgo/pull/1842<switch>, as empty containers can be used for attributes like requiredFeatures. By @vincentbernat in https://github.com/svg/svgo/pull/1747.d.ts file extension instead of .ts. By @Exotelis in https://github.com/svg/svgo/pull/1780#loadConfig method. By @nuintun in https://github.com/svg/svgo/pull/1844Before and after using vectors from various sources, with the default preset of each respective version:
| SVG | Original | v3.0.4 | v3.0.5 | Delta |
|---|---|---|---|---|
| Arch Linux Logo | 9.529 KiB | 4.735 KiB | 4.608 KiB | ⬇️ 0.127 KiB |
| Blobs | 50.45 KiB | 42.949 KiB | 42.949 KiB | |
| Isometric Madness | 869.034 KiB | 550.593 KiB | 550.153 KiB | ⬇️ 0.44 KiB |
| tldr-pages Banner | 2.071 KiB | 1.07 KiB | 1.07 KiB | |
| Wikipedia Logo | 161.551 KiB | 117.152 KiB | 117.146 KiB | ⬇️ 0.006 KiB |
Before and after of the browser bundle of each respective version:
| v3.0.4 | v3.0.5 | Delta | |
|---|---|---|---|
| svgo.browser.js | 656.9 kB | 657.5 kB | ⬆️ 0.6 kB |
Includes various bug fixes for existing plugins and a new optimization. Also splits removeXMLNS, which removed XLink, into two separate plugins, remov
Includes various bug fixes for existing plugins and a new optimization. Also splits removeXMLNS, which removed XLink, into two separate plugins, removeXMLNS and removeXlink.
xmlns:xlink) namespace. If that is desirable, you should enable the new removeXlink plugin, which does more while being safer. By @TrySound and @SethFalco in https://github.com/svg/svgo/pull/1535pre elements in foreignObject. By @SethFalco in https://github.com/svg/svgo/pull/1796@-webkit-keyframes in <style> node. By @SethFalco in https://github.com/svg/svgo/pull/1826z command if going back to initial position, or drop z if redundant. By @KTibow in https://github.com/svg/svgo/pull/1822xmlns:xlink) namespace and migrates from XLink attributes to the SVG 2 equivalent. Disabled by default. By @TrySound and @SethFalco in https://github.com/svg/svgo/pull/1535Before and after using vectors from various sources, with the default preset of each respective version:
| SVG | Original | v3.0.3 | v3.0.4 | Delta |
|---|---|---|---|---|
| Arch Linux Logo | 9.529 KiB | 4.738 KiB | 4.735 KiB | ⬇️ 0.003 KiB |
| Blobs | 50.45 KiB | 42.949 KiB | 42.949 KiB | |
| Isometric Madness | 869.034 KiB | 550.699 KiB | 550.593 KiB | ⬇️ 0.106 KiB |
| tldr-pages Banner | 2.071 KiB | 1.07 KiB | 1.07 KiB | |
| Wikipedia Logo | 161.552 KiB | 118.441 KiB | 117.152 KiB | ⬇️ 1.289 KiB |
Before and after of the browser bundle of each respective version:
| v3.0.3 | v3.0.4 | Delta | |
|---|---|---|---|
| svgo.browser.js | 651.7 kB | 656.9 kB | ⬆️ 5.2 kB |
Replace webpack loader library in README as previous was deprecated. By @tanyabouman in https://github.com/svg/svgo/pull/1771
Includes various bug fixes and optimizations for existing plugins.
We're also revamped the documentation for the project. You can find it on svgo.dev! The frontend for svgo.dev is maintained in svg/svgo.dev, contributions are welcome.
preservePatterns parameter. Preserves legal comments by default, same as the previous behavior, but can now be overridden. By @SethFalco in https://github.com/svg/svgo/pull/1812removeAny parameter to false by default for accessibility. By @SethFalco in https://github.com/svg/svgo/pull/1806defs children after optimization. By @SethFalco in https://github.com/svg/svgo/pull/1785null, undefined, or empty plugin. Instead, log a warning and ignore it. By @SethFalco in https://github.com/svg/svgo/issues/1128on*) and href attributes with javascript: URIs. By @cakeinpanic and @SethFalco in https://github.com/svg/svgo/pull/1807, https://github.com/svg/svgo/pull/1818, https://github.com/svg/svgo/pull/1819, https://github.com/svg/svgo/pull/1820Before and after using vectors from various sources, with the default preset of each respective version:
| SVG | Original | v3.0.2 | v3.0.3 | Delta |
|---|---|---|---|---|
| Arch Linux Logo | 8.584 KiB | 4.748 KiB | 4.747 KiB | ⬇️ 0.001 KiB |
| Blobs | 50.45 KiB | 42.949 KiB | 42.949 KiB | |
| Isometric Madness | 869.034 KiB | 550.829 KiB | 550.699 KiB | ⬇️ 0.13 KiB |
| tldr-pages Banner | 2.071 KiB | 1.07 KiB | 1.07 KiB | |
| Wikipedia Logo | 161.552 KiB | 118.441 KiB | 118.441 KiB |
Before and after of the browser bundle of each respective version:
| v3.0.2 | v3.0.3 | Delta | |
|---|---|---|---|
| svgo.browser.js | 643.5 kB | 651.7 kB | ⬆️ 8.2 kB |
Installing @types/csso no longer required
Installing @types/csso no longer required
store exposed types only in .d.ts files, no longer need to enable js checking
Thanks to @Kreeg, @XhmikosR and @TrySound
fixed datauri option when multipass is not enabled
datauri option when multipass is not enabledPlease refer to the Migration Guide from v2 to v3 for a more concise version!
Typescript types are exposed out of the box. No longer need to install @types/svgo
// svgo.config.js
/**
* @type {import('svgo').Config}
*/
export default {
// svgo configuration
}
Active flag is no longer supported
export default {
plugins: [
{
name: 'removeDoctype',
active: true
},
{
name: 'removeComments',
active: false
}
]
}
extendDefaultPlugins is removed, preset-default plugin should be used instead
when need to customize plugins defaults
export default {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
// plugins customization
}
}
}
]
}
Enabled sortAttrs plugin by default to get better gzip compression.
<svg>
- <rect fill-opacity="" stroke="" fill="" stroke-opacity="" />
+ <rect fill="" fill-opacity="" stroke="" stroke-opacity="" />
</svg>
Can be disabled if necessary
export default {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
sortAttrs: false
}
}
}
]
}
cleanupIDs plugin is renamed to cleanupIds
export default {
plugins: [
'cleanupIds'
]
}
// or
export default {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
cleanupIds: {}
}
}
}
]
}
Removed cleanupIds plugin "prefix" param, prefixIds should be used instead
export default {
plugins: [
'cleanupIds',
{
name: 'prefixIds',
params: {
prefix: 'my-prefix'
}
}
]
}
Removed width and height from optimization result.
const { width, height } = optimize(svg).info
Can be found with custom plugin
let width = null
let height = null
const plugin = {
name: 'find-size',
fn: () => {
return {
element: {
enter: (node, parentNode) => {
if (parentNode.type === 'root') {
width = node.attributes.width
height = node.attributes.height
}
}
}
}
}
}
optimize(svg, {
plugins: ['preset-default', plugin]
})
Removed error and modernError from optimization result
const {data, error, modernError } = optimize(svg)
Now all errors are thrown, parsing error can be checked by name
try {
const { data } = optimize(svg)
} catch (error) {
if (error.name === 'SvgoParserError') {
// formatted error
error.toString()
} else {
// runtime error
}
}
Removed full, perItem and perItemReverse plugin types.
visitor is the only supported plugin API so plugin.type is no longer required.
Removed plugin.active flag.
Removed plugin.params used as default params, destructuring with defaults can be used instead
name and fn are only required now
const plugin = {
name: 'my-custom-plugin',
fn: (root, params) => {
const { myParam = true } = params
return {}
}
}
Removed createContentItem and JSAPI class from nodes.
All nodes are now plain objects with one exception.
parentNode need to be defined to not break builtin plugins.
const plugin = {
name: 'my-custom-plugin',
fn: () => {
return {
element: {
enter: (node) => {
if (node === 'g') {
const child = {
type: 'element',
name: 'g',
attributes: {},
children: []
}
Object.defineProperty(child, 'parentNode', {
writable: true,
value: node,
})
node.children.push(child)
}
}
}
}
}
}
Thanks to @istarkov, @boidolr, @deining, @ranman, @mondeja, @liamcmitchell-sc, @rogierslag, @kriskowal, @hugolpz and @TrySound
SVGO v2 is not officially supported; please consider upgrading to SVGO v4. This security fix has been backported, but there is no commitment to backpo…
removeScriptElement hardening from SVGO v4 in #2272:
data: URLs and legacy vbscript: URLs<foreignObject> elementsThis addresses GHSA-4vpr-x523-8j87 and GHSA-w27v-7q3p-w38r for the v2 release line.
SVGO v2 is not officially supported; please consider upgrading to SVGO v4. This security fix has been backported, but there is no commitment to backport more complex changes in the future.
removeScriptElement , make <script> handling namespace aware. By @SethFalco
<script> handling namespace aware. By @SethFalcoSVGO v2 is not officially supported, please consider upgrading to SVGO v4 instead. We've backported this fix as there are security implications, but there is no commitment to do this for more complex changes in future.
Consider reading our Migration Guide from v2 to v3 and Migration Guide from v3 to v4 which should ease the process.
We'll deprecate v2.8.1, and I'll include the change log here.
This is effectively just a re-release of SVGO v2.8.1, but with *.test.js files omitted. It seems something was wrong with the configuration in the v2.8.0 tag and I hadn't noticed it included a few extra files. 😅
We'll deprecate v2.8.1, and I'll include the change log here.
Before and after of the browser bundle of each respective version:
| v2.8.0 | v2.8.2 | Delta | |
|---|---|---|---|
| svgo.browser.js | 587.2 kB | 589.2 kB | ⬆️ 2 kB |
SVGO v2 is not officially supported, please consider upgrading to SVGO v4 instead. We've backported this fix as there are security implications, but there is no commitment to do this for more complex changes in future.
Consider reading our Migration Guide from v2 to v3 and Migration Guide from v3 to v4 which should ease the process.
This release left *.test.js files in the package, which have been omitted in v2.8.2. Sorry for the noise!
This release left *.test.js files in the package, which have been omitted in v2.8.2. Sorry for the noise!
Before and after of the browser bundle of each respective version:
| v2.8.0 | v2.8.1 | Delta | |
|---|---|---|---|
| svgo.browser.js | 587.2 kB | 589.2 kB | ⬆️ 2 kB |
SVGO v2 is not officially supported, please consider upgrading to SVGO v4 instead. We've backported this fix as there are security implications, but there is no commitment to do this for more complex changes in future.
Consider reading our Migration Guide from v2 to v3 and Migration Guide from v3 to v4 which should ease the process.
If you enjoy SVGO and would like to support our work, consider sponsoring us directly via our OpenCollective.
If you enjoy SVGO and would like to support our work, consider sponsoring us directly via our OpenCollective.
Join us in our discord
xmlns:xlink attribute (https://github.com/svg/svgo/pull/1508)require to fix segfaults in linux (https://github.com/svg/svgo/pull/1605)I found some users are trying to enable plugins which are not part of default preset, for example
{
name: 'preset-default',
params: {
overrides: {
cleanupListOfValues: true
}
}
}
To fix this I made docs more concrete about plugin (https://github.com/svg/svgo/commit/5165ccb9d1f116b26a30a020e65aadd666012cb1) and introduced a warning when true is specified in overrides (https://github.com/svg/svgo/commit/cb7e9be623b6e2fbbfcb9b67c4c85131e1477925). Please give us feedback if you still have issues.
Thanks to @IlyaSkriblovsky, @devongovett, @matheus1lva, @omgovich, @renatorib and @TrySound
If you enjoy SVGO and would like to support our work, consider sponsoring us directly via our OpenCollective.
If you enjoy SVGO and would like to support our work, consider sponsoring us directly via our OpenCollective.
Join us in our discord
This release adds support for es modules in svgo.config.js when package.json type field is "module". For projects with mixed cjs and esm svgo.config.mjs and svgo.config.cjs are also supported as fallback.
See https://github.com/svg/svgo/pull/1583
export default {
plugins: [
'preset-default'
]
}
Follwing plugins are migrated to the new visitor plugin api and covered with tsdoc
Other internal changes
Thanks to @renatorib, @matheus1lva, @omgovich, @deepsweet, @ai, @samouss and @TrySound
fixed optimize(svg) usage without config
optimize(svg) usage without config (https://github.com/svg/svgo/pull/1573)Thanks to @XhmikosR, @thewilkybarkid, @renatorib, @matheus1lva, @omgovich and @TrySound
If you enjoy SVGO and would like to support our work, consider sponsoring us directly via our OpenCollective.
If you enjoy SVGO and would like to support our work, consider sponsoring us directly via our OpenCollective.
We have some good stuff in this release
Before people struggled to figure out what and why happens with such cryptic error
Error: Error in parsing SVG: Unquoted attribute value
Line: 1
Column: 29
Char: 6
File: input.svg
This gives too little information when a lot of svgs are transformed.
New errors look like this, include context and point to exact location with the issue. We hope this will solve many issues when dealing with bundlers and other tools integrations.
Error: SvgoParserError: input.svg:2:29: Unquoted attribute value
1 | <svg viewBox="0 0 120 120">
> 2 | <circle fill="#ff0000" cx=60.444444" cy="60" r="50"/>
| ^
3 | </svg>
4 |
To get better compression results SVGO uses multipass option. This option is used to run prefixIds plugin only once to prefix ids and classes properly.
Though sometimes users run svgo manually a few times which leads to duplicated prefixes and make code much bigger. To solves this prefixIds was redesigned to add prefix only when it does not exit in ids and classes.
Eventually all plugins are planned to be determenistic and idempotent so multipass option would not be necessary and single pass compression could be as effective as possible.
js2svg.eol: 'lf' | 'crlf'
Allows to customize end of line characters which is usually resolved by os.EOL in node.
finalNewline: boolean
Ensures SVG output has a final newline which is required for some tools like git.
Follwing plugins are migrated to the new visitor plugin api and covered with tsdoc
Also fixed a few bugs
Thanks to @XhmikosR, @matheus1lva, @deepsweet, @omgovich, @adalinesimonian and @TrySound
In this release we have a couple of fixes
In this release we have a couple of fixes
Visitor api now get parentNode in enter and exit callback
return {
element: {
enter: (node, parentNode) => {
},
exit: (node, parentNode) => {
}
}
}
And a lot of plugins are migrated to visitor api and covered them with tsdoc
Thanks to @XhmikosR, @morganney, @oBusk, @matheus1lva and @TrySound
In this release I happy to introduce the new plugin "preset-default" which allows to declaratively setup and customize default set of plugins. Previou
Hey everybody!
In this release I happy to introduce the new plugin "preset-default" which allows to declaratively setup and customize default set of plugins. Previous solution extendDefaultPlugins utility prevented parcel users from using cachable json config, svgo-loader and svgo-jsx required svgo to be installed locally. "preset-default" plugin is just another builtin plugi.
module.exports = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
// customize options
builtinPluginName: {
optionName: 'optionValue',
},
// or disable plugins
anotherBuiltinPlugin: false,
},
},
},
],
};
We also fixed a few bugs
Thanks to @TrySound, @ydaniv, @ludofischer, @XhmikosR and @joseprio
Fixed vulnerability in css-select dependency
Fixed vulnerability in css-select dependency (https://github.com/svg/svgo/pull/1485)
Thanks to @ericcornelissen
Hey, everybody! We have a big release here.
Hey, everybody! We have a big release here.
Before:
<svg>
<style media="print">
.st0{ fill:red; padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; }
</style>
<style>
.test { background: red; }
</style>
</svg>
After:
<svg>
<style>
@media print{
.st0{ fill:red; padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; }
}
.test { background: red; }
</style>
</svg>
--exclude flag which uses regexps to exclude some files from --folder. See #1409svgo --folder=svgs --exclude "invalid-icon" "bad-.+"
Internal AST is migrated to XAST. This spec makes maintaining plugins easier and may be used as interop with other tools like SVGR.
The new visitor plugin type combines features of "full", "perItem" and "perItemReverse" plugins without loosing simplicity. Eventually only visitor api will be supported. See #1454
Also small fixes
Thanks to @chambo-e, @strarsis, @XhmikosR, @omgovich and @TrySound
ignore keyframes in computeStyle
This is a big patch with new style computing (https://github.com/svg/svgo/pull/1399) and landed to master regression tests
This is a big patch with new style computing (https://github.com/svg/svgo/pull/1399) and landed to master regression tests
A lot of bugs are fixed
<style> type attribute in inlineStyles plugin (https://github.com/svg/svgo/pull/1400)<style> support in removeHiddenElems plugin (https://github.com/svg/svgo/pull/1399)<style> support when removing useless path commands (https://github.com/svg/svgo/commit/c21fef54e1aede8cf9f4b4b73ab79d91b7907d2b)<style> support when combining path commands (https://github.com/svg/svgo/commit/ba7e9bdc0d4ee677336f09b6fb24fd6cc866e97d)<pattern> when at least one argument is present (https://github.com/svg/svgo/commit/0e6b0c4a0182fb79775fb6af2f1df18c12f917d9)<marker> with display none (https://github.com/svg/svgo/commit/d3e3726ac42bf623572ff06405e12f4ee72873dd)<svg> (https://github.com/svg/svgo/commit/28c01cfe65cd87796fb061fe3ede7c6f59d0e1f6)435 of 526 regression tests are passing
Thanks to @XhmikosR @sk- and @TrySound
Wow, two minor releases in a row. There is a big reason for that. We got a new logo! See it in readme. Big thanks to @DerianAndre.
Wow, two minor releases in a row. There is a big reason for that. We got a new logo! See it in readme. Big thanks to @DerianAndre.
There were also implemented brand new path data parser and stringifier (https://github.com/svg/svgo/pull/1378 and https://github.com/svg/svgo/pull/1387) to do more reliable transformations and produce smaller svg.
A cup of small fixes
<tspan> inside <a> (https://github.com/svg/svgo/commit/091172a392f6d751855477d51e5c8bd3e44fde97)Thanks to @sk- @XhmikosR @deepsweet and @TrySound
This release introduced two big changes
This release introduced two big changes
See fixed bugs
<svg /> with enabled cleanupIDs plugin (https://github.com/svg/svgo/commit/9b97e06ef69b7961f342c9ee8468c552c9b503a3)--config flag does not exist or json string is specified (https://github.com/svg/svgo/commit/a855b40ec5d53f3ce3b45213fd4c65bc4dc05347)xml:space="preserve" (https://github.com/svg/svgo/commit/776ec1e71bcd2aa768b2d3ac987177f706834547)<g> when filter attribute is specified (https://github.com/svg/svgo/commit/c1d5f0f7a93a6f1c947baa5860ddd40f8d1bb701)Thanks to @XhmikosR @sk- @chromakode @devongovett and @TrySound
reduced browser build size 1450kB -> 820kB
<defs> by reusePaths plugin (https://github.com/svg/svgo/pull/1201)rx or ry attributes are not specified (https://github.com/svg/svgo/commit/7f4e05297ade6747a2b6ca63109d75dc9c4ea3c0)<mask> (https://github.com/svg/svgo/commit/4490d62ee9f83febeb18f4a83a297c544459514a)<path> by default to support many broken non-browser environments (https://github.com/svg/svgo/pull/1353)Thanks to @ChrisRu @XhmikosR @yisibl @TrySound
removed unsafe usage of Buffer constructor
Thanks to @XhmikosR and @TrySound
fixed path intersection in mergePaths plugin
--indent flag in CLI (https://github.com/svg/svgo/pull/1331)Thanks to @sk- @Brooooooklyn @strarsis @AlpayY @TrySound
Happy to introduce SVGO 2.0. Package size was drastically reduced. Configuration is heavily simplified. Node 10.13+ is required.
Happy to introduce SVGO 2.0. Package size was drastically reduced. Configuration is heavily simplified. Node 10.13+ is required.
Since early versions plugins configuration was affected by yaml syntax. Though it was not practial in json or javascript for writing and for internal work.
plugins:
- removeViewBox: true
- removeAttr:
attrs: '(fill|stroke)'
{
plugins: [
{
removeViewBox: true
},
{
removeAttr: {
attrs: '(fill|stroke)'
}
}
]
}
In the new version plugins configuration is closer to internal representation.
{
plugins: [
{
name: 'removeViewBox'
},
{
name: 'removeAttr',
params: {
attrs: '(fill|stroke)'
}
}
]
}
In v1 full flag allowed to disable all default plugins and run only specified
in plugins list. In v2 it's default behaviour. To extend default plugins list
you can use extendDefaultPlugins utility.
{
plugins: extendDefaultPlugins([
{
name: 'removeViewBox',
active: false,
}
])
}
Loading custom plugin by path was removed in favour of manual import or require.
+const customPlugin = require('./custom-plugin.js')
{
plugins: [
{
name: 'customPlugin',
- path: './custom-plugin.js'
+ ...customPlugin
}
]
}
Painful coa was replaced with well maintained commander.
--enable and --disable flags are removed. In later versions we will explore
plugins setup via CLI.
Inlined json config is no longer suppored. CLI flags should be used instead.
--config="{multipass:true}"
By default SVGO CLI will search for svgo.config.js. --config flag allows
to specify js config with any name.
YAML and JSON configuration is no longer supported for the sake of simplicity and less dependencies.
Initially SVGO was implemented with callback style api to fit sax recommendation. Though in practice api was synchronous and allowed to access the result assigned in callback right after optimisation.
For v1 callback style was replaced with promise api which cannot longer be run synchronously. This was a pain point for many tools and required hacking svgo.
In v2 this pain is considered and api is now synchronous. No hacks necessary.
SVGO class is replaced with optimize function.
-const { SVGO } = require('svgo')
-const svgo = new SVGO({
- // config
- multipass: true
-})
-svgo.optimize(svgstring, { path: './file.svg' }).then(result => {
- ...
-})
+const { optimize, extendDefaultPlugins } = require('svgo')
+optimize(svgstring, {
+ path: './file.svg',
+ multipass: true,
+})
Some tools require the same logic for resolving svgo config as SVGO CLI.
const { loadConfig, optimize } = require('svgo')
...
const config = await loadConfig()
optimize(svgstring, { path: './file.svg', ...config })
There were a lot of request for this feature in the past.
Now tools like svgomg may use official and tested es module for browsers with optimize, extendDefaultPlugins and createContentItem support.
import {
optimize,
extendDefaultPlugins,
createContentItem
} from 'svgo/dist/svgo.browser.js'
Fixed TypeError: Cannot set property 'multipassCount' of undefined
Updated CSSO version to 4.0.2 fixing the issue with empty semicolons ";;" in styles (thanks to @strarsis and @lahmatiy).
prefixIds plugin now runs only once with --multipass option (by @strarsis).cleanupIDs plugin is prevented from producing a preserved ID, including one which matches a preserved prefix, when minifying (by @thomsj).Custom plugins now can be loaded from external js through path plugin param.
path plugin param.convertEllipseToCircle to convert ellipse with equal radius measures to circle (by @tigt).sortDefsChildren for improved compression (by @davidleston).arcto path command flags.removeDimensions plugin now adds viewBox if it's missing (by @adipascu).removeUnusedNS not counting attributes in <svg> tag itself.convertTransform due to rounding error leading to illegal value.force option for mergePaths plugin (by @goyney).prefixIds plugin for selectively prefixing IDs and/or classes (by @strarsis).Update js-yaml for Code Injection warning (by @kaungst).
Bump up js-yaml version to fix DoS vulnerability (by @eugestarr).
Some goodness from pull-requests.
Some goodness from pull-requests.
Some goodness from pull-requests.
--recursive option to process folders recursevely with option -f (by @dartess).removeAttributesBySelector plugin to remove elements matching a css selector (by @bmease).removeOffCanvasPaths plugin to remove elements outside of the viewbox (by @JoshyPHP).removeAttrs plugin: added preserveCurrentColor color (by @roblevintennis) and 3rd optional filter for a value (by @Herman-Freund).reusePaths plugin to replace duplicated elements with link (by @jhowcrof).--disable and --enable options (by @jmwebservices).cleanupIDs plugin (by @bkotzz).colors dependency with chalk (by @xPaw).Fixed crash in SVGO.optimize() when ‘info’ is absent.
SVGO.optimize() when ‘info’ is absent.cleanupListOfValues plugin.Fixed collapseGroups plugin removing property with a child having inherit value.
collapseGroups plugin removing property with a child having inherit value.version attribute value is not more being rounded.clone method with respect to the introduced CSS classes.vector-effect="non-scaling-stroke" (by @alexjlockwood).collapseGroups plugin if child have a filter (by @stristr).viewBox separators parsing.removeNonInheritableGroupAttrs plugin to work as intended.stroke-linecap.removeUnknownsAndDefaults plugin removing attributes from elements with id.collapseGroups plugin affecting <switch> and its subgroups.convertTransform plugin converting to rotate() with wrong sign in some case.cleanupListOfValues plugin not preserving non-numeric values.!important being passed to attributes in convertStyleToAttrs plugin.keepImportant to convertStyleToAttrs plugin to preserve styles with !important.removeHiddenElems plugin now also removes elements with visibility="hidden" attribute (by @mikolaj92).forceAbsolutePath option to convertPathData plugin to always use absolute coordinates (by @cool).keepRoleAttr for removeUnknownsAndDefaults plugin to preserve role- attributes (by @himedlooff).xmlns order option in sortAttrs plugin (by @hellatan).prefixIds plugin to pass prefix as false or as a function that returns false (by @vzaidman).prefixIds plugin now adds prefix to every class (by @vzaidman).Fixed issue with prefixIDs plugin not replacing url() values correctly (by @harrisjose).
Fixed issue with prefixIDs plugin not replacing url() values correctly (by @harrisjose).
Fixed bug with removing groups that are direct child of .
<switch>.Fixed removeViewBox plugin to check for zero start coordinates.
removeViewBox plugin to check for zero start coordinates.Fixed a couple of errors related to inlineStyles plugin.
inlineStyles plugin.Fixed error “Object.defineProperty called on non-object” in images with .
<foreignObject/>.SVGO now requires Node 4 or higher.
svgo *.svg syntax.SVGO.optimize() now returns Promise.datauri option to JS API.href attribute.cleanupIDs now don't removes IDs if an image consists only of defs.inlineStyles for converting styles from <style> element to attributes if possible (by @strarsis).cleanupNumericValues now rounds values in viewBox (by @caub).removeScriptElement (disabled by default) to align with removeStyleElement (by @pklingem).minifyStyles now removes styles based on usage with controlling options (by @lahmatiy).except in cleanupIDs to keep IDs (by @Velenir).force in cleanupIDs to work even if SVG contains style or script elements (by @Velenir).scale parameters (by @JoshyPHP).removeUselessStrokeAndFill to check for style or script elements per file (by @caub).keepAriaAttrs in removeUnknownsAndDefaults (by @davidtheclark).cleanupIDs to account animation syntax (by @caub).#ff0000 now converts to red as well as #f00 (by @davidleston).removeAttrs now can be changed per elemSeparator option (by @mikestreety).addAttributesToSVGElement now can add values to attributes.Extended currentColor match conditions (string, rx, bool) (by @AlimovSV)
currentColor match conditions (string, rx, bool) (by @AlimovSV)<animate> in <stop>.removeUnknownsAndDefaults.Reverted the requirement of Node.js to version 0.10.
addAttributesToSVGElement to the default config to allow using it with --enable option.Your coding agent can read these notes before it upgrades. Set up the MCP server →