svgo

⚙️ Node.js tool for optimizing SVG files

MIT License

Downloads
72.5M
Stars
20.4K
Committers
219

Bot releases are hidden (Show)

svgo -

Published by TrySound over 3 years ago

Thanks to @ChrisRu @XhmikosR @yisibl @TrySound

svgo -

Published by TrySound over 3 years ago

Thanks to @XhmikosR and @TrySound

svgo -

Published by TrySound over 3 years ago

Thanks to @sk- @Brooooooklyn @strarsis @AlpayY @TrySound

svgo -

Published by TrySound over 3 years ago

Happy to introduce SVGO 2.0. Package size was drastically reduced. Configuration
is heavily simplified. Node 10.13+ is required.

  • smaller install size
  • simplified config format
  • added browser ready es module bundle
  • API is synchronous
  • support only svgo.config.js for external configuration

Config changes

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
     }
   ]
 }

CLI changes

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.

Node API changes

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 })

Browser ready bundle

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'
svgo - 1.3.2 / 30.10.2019

Published by GreLI almost 5 years ago

  • Fixed TypeError: Cannot set property 'multipassCount' of undefined
svgo - 1.3.1 / 29.10.2019

Published by GreLI almost 5 years ago

  • 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).
svgo - 1.3.0 / 14.07.2019

Published by GreLI over 5 years ago

  • Custom plugins now can be loaded from external js through path plugin param.
  • New plugin convertEllipseToCircle to convert ellipse with equal radius measures to circle (by @tigt).
  • New plugin sortDefsChildren for improved compression (by @davidleston).
  • SVGO now removes unnecessary spaces after arcto path command flags.
  • removeDimensions plugin now adds viewBox if it's missing (by @adipascu).
  • Fixed removeUnusedNS not counting attributes in <svg> tag itself.
  • Fixed an issue with incorrect processing multiple images (by @cyberalien).
  • Fixed an error with incorrect converting multiple segmented curve to an arc.
  • Fixed an error with matrix decomposition in convertTransform due to rounding error leading to illegal value.
  • Added force option for mergePaths plugin (by @goyney).
  • Added options to prefixIds plugin for selectively prefixing IDs and/or classes (by @strarsis).
  • Exported config function (by @1000ch).
svgo - 1.2.2 / 16.04.2019

Published by GreLI over 5 years ago

  • Update js-yaml for Code Injection warning (by @kaungst).
svgo - 1.2.1 / 04.04.2019

Published by deepsweet over 5 years ago

Some goodness from pull-requests.

  • Bump up js-yaml version to fix DoS vulnerability (by @eugestarr).
svgo - 1.2.0 / 24.02.2019

Published by GreLI over 5 years ago

Some goodness from pull-requests.

  • Fixed extra blank lines when processing many files (by @panczarny).
  • Added --recursive option to process folders recursevely with option -f (by @dartess).
  • Added removeAttributesBySelector plugin to remove elements matching a css selector (by @bmease).
  • Added 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).
  • Added reusePaths plugin to replace duplicated elements with link (by @jhowcrof).
  • Added support of comma-separated plugins list in --disable and --enable options (by @jmwebservices).
  • Added option to preserve IDs based on prefix in cleanupIDs plugin (by @bkotzz).
  • Replaced colors dependency with chalk (by @xPaw).
svgo - 1.1.1 / 17.09.2018

Published by GreLI about 6 years ago

  • Fixed crash in SVGO.optimize() when ‘info’ is absent.
  • Removed extra space after cleanupListOfValues plugin.
svgo - 1.1.0 / 16.09.2018

Published by GreLI about 6 years ago

  • Fixed collapseGroups plugin removing property with a child having inherit value.
  • version attribute value is not more being rounded.
  • Fixed jsAPI clone method with respect to the introduced CSS classes.
  • Fixed scaling strokes with vector-effect="non-scaling-stroke" (by @alexjlockwood).
  • Fixed passing properties from groups in collapseGroups plugin if child have a filter (by @stristr).
  • Fixed arc path commands parsing without separators after flags, effectively producing a JS error.
  • Fixed viewBox separators parsing.
  • Fixed removeNonInheritableGroupAttrs plugin to work as intended.
  • Fixed removing path segments without length in presence of stroke-linecap.
  • Fixed removeUnknownsAndDefaults plugin removing attributes from elements with id.
  • Fixed converting to large arcs from nearly straight lines curves.
  • Fixed collapseGroups plugin affecting <switch> and its subgroups.
  • Fixed convertTransform plugin converting to rotate() with wrong sign in some case.
  • Fixed cleanupListOfValues plugin not preserving non-numeric values.
  • Fixed !important being passed to attributes in convertStyleToAttrs plugin.
  • Added option keepImportant to convertStyleToAttrs plugin to preserve styles with !important.
  • removeHiddenElems plugin now also removes elements with visibility="hidden" attribute (by @mikolaj92).
  • Added forceAbsolutePath option to convertPathData plugin to always use absolute coordinates (by @cool).
  • Added keepRoleAttr for removeUnknownsAndDefaults plugin to preserve role- attributes (by @himedlooff).
  • Added xmlns order option in sortAttrs plugin (by @hellatan).
  • Added an option to 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).
  • Updated and improved docs a bit (multiple authors).
svgo - 1.0.5 / 26.02.2018

Published by GreLI over 6 years ago

Fixed issue with prefixIDs plugin not replacing url() values correctly (by @harrisjose).

svgo - 1.0.4 / 30.01.2018

Published by GreLI over 6 years ago

  • Fixed bug with removing groups that are direct child of <switch>.
  • Fixed bug with shorthand path points counting (thanks @alexjlockwood for noticing).
  • Fixed crash on parsing invalid transform, e.g. without close parenthesis.
svgo - 1.0.3 / 08.11.2017

Published by GreLI almost 7 years ago

  • Fixed removeViewBox plugin to check for zero start coordinates.
  • Removed extra info from STDOUT when it set to output.
svgo - 1.0.2 / 03.11.2017

Published by GreLI almost 7 years ago

  • Fixed a couple of errors related to inlineStyles plugin.
  • Updated some lost details in documentation to reflect v1.0 changes.
svgo - 1.0.1 / 31.10.2017

Published by GreLI almost 7 years ago

  • Fixed error “Object.defineProperty called on non-object” in images with <foreignObject/>.
svgo - 1.0.0 / 30.10.2017

Published by GreLI almost 7 years ago

  • SVGO now requires Node 4 or higher.
  • Changed CLI syntax to treat filenames as input, thus allowing svgo *.svg syntax.
  • SVGO.optimize() now returns Promise.
  • Added datauri option to JS API.
  • Added support for SVG 2 href attribute.
  • cleanupIDs now don't removes IDs if an image consists only of defs.
  • New plugin inlineStyles for converting styles from <style> element to attributes if possible (by @strarsis).
  • cleanupNumericValues now rounds values in viewBox (by @caub).
  • New plugin: removeScriptElement (disabled by default) to align with removeStyleElement (by @pklingem).
  • minifyStyles now removes styles based on usage with controlling options (by @lahmatiy).
  • New option except in cleanupIDs to keep IDs (by @Velenir).
  • New option force in cleanupIDs to work even if SVG contains style or script elements (by @Velenir).
  • Fixed arcs transforming with different signed scale parameters (by @JoshyPHP).
  • Fixed removeUselessStrokeAndFill to check for style or script elements per file (by @caub).
  • New option keepAriaAttrs in removeUnknownsAndDefaults (by @davidtheclark).
  • Corrected parsing in cleanupIDs to account animation syntax (by @caub).
  • #ff0000 now converts to red as well as #f00 (by @davidleston).
  • Added “gray” variation to colors list per CSS Color Module Level 4 (by @ydaniv).
  • Fixed error on empty files.
  • A separator character in removeAttrs now can be changed per elemSeparator option (by @mikestreety).
  • addAttributesToSVGElement now can add values to attributes.
svgo - 0.7.2 / 29.01.2017

Published by GreLI over 7 years ago

  • Extended currentColor match conditions (string, rx, bool) (by @AlimovSV)
  • Fixed removing <animate> in <stop>.
  • Fixed removing same transform in inner element in removeUnknownsAndDefaults.
  • Fixed collapsing groups with same non-inheritable attribue.
  • Corrected removing of leading zero in case of exponential notation.
svgo - 0.7.1 / 27.09.2016

Published by GreLI about 8 years ago

  • Reverted the requirement of Node.js to version 0.10.
  • Added addAttributesToSVGElement to the default config to allow using it with --enable option.
  • Added korean translation of “How it works” doc (by @primeiros).
Package Rankings
Top 0.29% on Npmjs.org
Top 11.86% on Repo1.maven.org
Top 13.23% on Formulae.brew.sh
Top 36.61% on Pypi.org
Top 3.54% on Proxy.golang.org
Badges
Extracted from project README
npm chat docs