⚙️ Node.js tool for optimizing SVG files
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.
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
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
<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
Thanks to @XhmikosR and @TrySound
--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.
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'
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).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).