Skip to content

Instantly share code, notes, and snippets.

@pladaria
Last active February 7, 2023 17:15
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pladaria/69321af86ce165c2c1fc1c718b098dd0 to your computer and use it in GitHub Desktop.
Save pladaria/69321af86ce165c2c1fc1c718b098dd0 to your computer and use it in GitHub Desktop.
SVGO config file
multipass: true
plugins:
- addAttributesToSVGElement: false
- addClassesToSVGElement: false
- cleanupAttrs: true
- cleanupEnableBackground: true
- cleanupIDs: true
- cleanupListOfValues: true
- cleanupNumericValues:
floatPrecision: 2
- collapseGroups: true
- convertColors: true
- convertPathData: true
- convertShapeToPath: true
- convertStyleToAttrs: true
- convertTransform: true
- mergePaths: true
- minifyStyles: true
- moveElemsAttrsToGroup: true
- moveGroupAttrsToElems: true
- removeAttrs: true
- removeComments: true
- removeDesc: true
- removeDimensions: true
- removeDoctype: true
- removeEditorsNSData: true
- removeElementsByAttr: true
- removeEmptyAttrs: true
- removeEmptyContainers: true
- removeEmptyText: true
- removeHiddenElems: true
- removeMetadata: true
- removeNonInheritableGroupAttrs: true
- removeRasterImages
- removeStyleElement: true
- removeTitle: true
- removeUnknownsAndDefaults: true
- removeUnusedNS: true
- removeUselessDefs: true
- removeUselessStrokeAndFill: true
- removeViewBox: true
- removeXMLNS: false
- removeXMLProcInst: true
- sortAttrs: true
- transformsWithOnePath: true
js2svg:
pretty: true
indent: ' '
@torkleyy
Copy link

torkleyy commented Aug 9, 2019

Thank you!

FYI, transformsWithOnePath seems to no longer exist: svg/svgo@8354897

@tomchen
Copy link

tomchen commented Jul 16, 2020

Thank you. I've been using this config for a while.

Just one thing. removeElementsByAttr normally has detailed parameters to specify by what attributes you want to remove the elements:

(json format)

removeElementsByAttr: { id: ['invisible'] }

But with

removeElementsByAttr: true

it seems SVGO removes all elements without any attributes (or with class only?).

An element without any attributes (or with class only?) is perfectly valid and this removal is likely not what you want.

So anyone who uses this could switch removeElementsByAttr to false

@VincentVToscano
Copy link

VincentVToscano commented Apr 12, 2022

Have any of you used this file via imagemin-cli? I am trying to pass the file above (with another option: removeScriptElement: true) but it doesnt seem to be working and I'm not getting an error. I still see <script> elements in the outputted svg. Thanks in advance.
imagemin ./assets/ --plugin.svgo --config=_build_configurations/svgo.config.yml

I've also tried it like this:
imagemin ./assets/ --plugin.svgo.config=_build_configurations/svgo.config.yml

@bramchi
Copy link

bramchi commented Aug 15, 2022

@VincentVToscano Any luck figuring that out? I'm having the same issue

@VincentVToscano
Copy link

@bramchi I have had no luck with what I mentioned above. I have also had no luck minifying JSON-LD between these tags:

<script type="application/ld+json">…</script>

Have you had any luck with either? 🤞

@bramchi
Copy link

bramchi commented Sep 27, 2022

@VincentVToscano Have you tried placing a regular svgo.config.js file alongside your package.json? That has given me some good results in the past for other packages. It gets picked up by the svgo core library, regardless of any config flags. Not sure a yml file will work, so make sure its a plain JavaScript file. It should contain something like this, a list of plugins that you want to enable:

module.exports = {
    plugins: [
      'removeDoctype',
      'removeXMLProcInst',
      'removeComments',
      'removeMetadata',
      'removeEditorsNSData',
      'cleanupAttrs',
      'inlineStyles',
      'minifyStyles',
      // 'cleanupIDs',
      'removeUselessDefs',
      'cleanupNumericValues',
      'convertColors',
      'removeUnknownsAndDefaults',
      'removeNonInheritableGroupAttrs',
      'removeUselessStrokeAndFill',
      // 'removeViewBox',
      'cleanupEnableBackground',
      'removeHiddenElems',
      'removeEmptyText',
      'convertShapeToPath',
      'convertEllipseToCircle',
      'moveElemsAttrsToGroup',
      'moveGroupAttrsToElems',
      'collapseGroups',
      'convertPathData',
      'convertTransform',
      'removeEmptyAttrs',
      'removeEmptyContainers',
      'mergePaths',
      'removeUnusedNS',
      'sortDefsChildren',
      'removeTitle',
      'removeDesc'
    ]
}

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