Skip to content

@TrySound TrySound released this Feb 17, 2021 · 79 commits to master since this release

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

    - 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.


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 {
} from 'svgo/dist/svgo.browser.js'
Assets 2