⚙️ Node.js tool for optimizing SVG files
MIT License
Bot releases are hidden (Show)
<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'
Published by GreLI almost 5 years ago
Published by GreLI almost 5 years ago
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).Published by GreLI over 5 years ago
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).Published by GreLI over 5 years ago
Published by deepsweet over 5 years ago
Some goodness from pull-requests.
Published by GreLI over 5 years ago
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).Published by GreLI about 6 years ago
SVGO.optimize()
when ‘info’ is absent.cleanupListOfValues
plugin.Published by GreLI about 6 years ago
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).Published by GreLI over 6 years ago
Fixed issue with prefixIDs plugin not replacing url() values correctly (by @harrisjose).
Published by GreLI over 6 years ago
<switch>
.Published by GreLI almost 7 years ago
removeViewBox
plugin to check for zero start coordinates.Published by GreLI almost 7 years ago
inlineStyles
plugin.Published by GreLI almost 7 years ago
<foreignObject/>
.Published by GreLI almost 7 years ago
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.Published by GreLI over 7 years ago
currentColor
match conditions (string, rx, bool) (by @AlimovSV)<animate>
in <stop>
.removeUnknownsAndDefaults
.Published by GreLI about 8 years ago
addAttributesToSVGElement
to the default config to allow using it with --enable
option.