Skip to content

Instantly share code, notes, and snippets.

@ahaywood
Last active March 28, 2025 20:18
Show Gist options
  • Save ahaywood/66044d7d2c61821a96ba5a56232094c7 to your computer and use it in GitHub Desktop.
Save ahaywood/66044d7d2c61821a96ba5a56232094c7 to your computer and use it in GitHub Desktop.
svgo Config File

This is a config file to be used with svgo's command line tool.

You can ues it with the following command:

svgo *.svg --config=/PATH-TO-FILE/svgo-config.yml
{
"plugins": [
{
"cleanupAttrs": true
},
{
"removeDoctype": true
},
{
"removeXMLProcInst": true
},
{
"removeComments": true
},
{
"removeMetadata": true
},
{
"removeTitle": true
},
{
"removeDesc": true
},
{
"removeUselessDefs": true
},
{
"removeEditorsNSData": true
},
{
"removeEmptyAttrs": true
},
{
"removeHiddenElems": true
},
{
"removeEmptyText": true
},
{
"removeEmptyContainers": true
},
{
"removeViewBox": false
},
{
"cleanUpEnableBackground": true
},
{
"convertStyleToAttrs": true
},
{
"convertColors": true
},
{
"convertPathData": true
},
{
"convertTransform": true
},
{
"removeUnknownsAndDefaults": true
},
{
"removeNonInheritableGroupAttrs": true
},
{
"removeUselessStrokeAndFill": true
},
{
"removeUnusedNS": true
},
{
"cleanupIDs": true
},
{
"cleanupNumericValues": true
},
{
"moveElemsAttrsToGroup": true
},
{
"moveGroupAttrsToElems": true
},
{
"collapseGroups": true
},
{
"removeRasterImages": false
},
{
"mergePaths": true
},
{
"convertShapeToPath": true
},
{
"sortAttrs": true
},
{
"transformsWithOnePath": false
},
{
"removeDimensions": true
},
{
"removeAttrs": { "attrs": "(stroke|fill)" }
}
]
}
@hsellik
Copy link

hsellik commented Feb 21, 2022

Something like this should result in a similar configuration for v2.x:

module.exports = {
    plugins: [
        {
            name: 'preset-default',
            params: {
                overrides: {
                    removeViewBox: false,
                    removeRasterImages: false,
                    transformsWithOnePath: false,
                },
            },
        },
        "cleanupEnableBackground",
        "cleanupAttrs",
        "removeDoctype",
        "removeXMLProcInst",
        "removeComments",
        "removeMetadata",
        "removeTitle",
        "removeDesc",
        "removeUselessDefs",
        "removeEditorsNSData",
        "removeEmptyAttrs",
        "removeHiddenElems",
        "removeEmptyText",
        "removeEmptyContainers",
        "convertStyleToAttrs",
        "convertColors",
        "convertPathData",
        "convertTransform",
        "removeUnknownsAndDefaults",
        "removeNonInheritableGroupAttrs",
        "removeUselessStrokeAndFill",
        "removeUnusedNS",
        "cleanupIDs",
        "cleanupNumericValues",
        "moveElemsAttrsToGroup",
        "moveGroupAttrsToElems",
        "collapseGroups",
        "mergePaths",
        "convertShapeToPath",
        "sortAttrs",
        "removeDimensions",
        {
            name: 'removeAttrs',
            params: {
                attrs: '(stroke|fill)',
            },
        },
    ],
};

@RadekJakGit
Copy link

RadekJakGit commented Jun 13, 2022

with this obsolete version it works!
https://www.npmjs.com/package/svgo/v/1.2.0
npm i -g [email protected]

@danxczm
Copy link

danxczm commented May 17, 2024

unfortunately doesn't work for me =(
--config Custom config file, only .js is supported

@jmvillanueva-dev
Copy link

jmvillanueva-dev commented Mar 28, 2025

Hello everyone! Is there anyone from 2025? πŸš€

If you want to follow up ahaywood tutorial, you have to update svgo-config.js for SVGO v3+, you might have noticed that some plugins have changed or been removed. Many older configurations no longer work, and you may see errors like:

❌ Error: Unknown builtin plugin "cleanupIDs" specified.

πŸ”Ή Key Changes in SVGO v3+

1️⃣ cleanupIDs has been removed – This plugin no longer exists, so remove it from your config.
2️⃣ removeAttrs now requires an array format – Use { attrs: ["stroke", "fill"] } instead of a regex.
3️⃣ preset-default includes essential optimizations – No need to manually list common plugins.
4️⃣ multipass: true is recommended – Enables multiple optimization passes for smaller file sizes.
5️⃣ The config file must be .js (not .json) – Use export default {} instead of JSON format.β€ΌοΈπŸš©

βœ… Working SVGO v3+ Configuration

Here's a valid svgo-config.js for 2025 and beyond:

export default {
  multipass: true, 
  js2svg: {
    indent: 2,
    pretty: false, 
  },
  plugins: [
    "preset-default",
    {
      name: "removeViewBox",
      active: false, 
    },
    {
      name: "removeDimensions",
      active: true,
    },
    {
      name: "removeAttrs",
      params: { attrs: ["stroke", "fill"] },
    },
    {
      name: "sortAttrs",
      active: true, 
    },
    {
      name: "mergePaths",
      active: true, 
    },
    {
      name: "convertStyleToAttrs",
      active: true,
    },
  ],
};

πŸ”Ή How to Use It

Run the following command in your terminal:

svgo *.svg --config=/PATH-TO-FILE/svgo-config.js

With this setup, your SVG optimization will be fully compatible with SVGO v3+ in 2025! πŸš€πŸŽ¨
Hope this helps! If you find new updates, feel free to share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment