Search code examples
svgnpm-scriptsimagemin

How to use plugin options with imagemin-cli?


I'm trying to use imagemin-cli for npm scripts, but there is no documentation for using plugin options.

The plugin I want to use is svgo and the option is removeDimensions=true, how would this look as an npm scripts command?

This is an example of a command I ran unsucessfully:

imagemin [--plugin=svgo --option=removeDimensions=true] src/img/** --out-dir=dist/img/


Solution

  • Imagemin-cli now supports a way to pass those options; some examples from the Readme:

    $ imagemin --plugin.pngquant.quality={0.1,0.2} foo.png > foo-optimized.png
    $ imagemin --plugin.webp.quality=95 --plugin.webp.preset=icon foo.png > foo-icon.webp
    

    Here are some examples that I'm currently using:

    $ imagemin --plugin.jpegoptim.progressive=true --plugin.jpegoptim.max=70 *.jpg --out-dir=./output
    $ imagemin --plugin.pngquant.quality={0.5,0.7} *.png --out-dir=./output
    

    If you're interested in the details, this was added in PR 23.