Optimize .svg from asstets with svgo

Tried to google and searched in this forum and github issues, but was unable to find any mentions.

I want to store original .svg files in assets and do optimize them with svgo (GitHub - svg/svgo: ⚙️ Node.js tool for optimizing SVG files) during hugo rendering. How to do it?

I suppose I have to write some custom code for Minify but there is no documentation about how to use external tools for optimizations.

You can’t. You have to process your SVG files outside of the hugo process. They are text files, not images per se and any image processing does not apply to SVG files. Pre-process them and put them into either the page bundle or the static directory.

More general: other external tools than the tools named in the documentation can’t run within the hugo command.

Hugo Pipes allows the minification of any CSS, JS, JSON, HTML, SVG or XML resource.

Look at this page in Hugo docs Asset minification | Hugo seems like Hugo is aware of what svg is and can minify why would you need an additional tool or move outside of Hugo process?

Hi @Nick_Knutov have you tried the Hugo minification I usually run the --minify and assumes it does the job. have you checked the svg’s with hugo --minify and not happy with the result?


SVGO removes unused definitions, optimises encoding of embedded images, optimised order of the tags, etc., etc. Minification is the least of its tasks.

1 Like

Opened feature request: Add custom external optimizer for files per extention · Issue #9802 · gohugoio/hugo · GitHub