Problem: You want to use imagemin-cli
but it requires you provide an
output directory. But you just want to override the existing file with the
optimized version.
Solution: This uses imagemin
with the plugins to support compressing
png
, jpg
, gif
, svg
, and webp
files and it overrides the existing file.
npx https://gist.github.com/kentcdodds/0edaef72e6fd9d52ab9f3ec9da3c0b51 ./glob/to/files/**/*.png
Or if you just want to optimize all the files in your project you can run it with arguments:
npx https://gist.github.com/kentcdodds/0edaef72e6fd9d52ab9f3ec9da3c0b51
This will automatically ignore any files in your .gitignore
if you have one
(otherwise it'll fallback to a good default).
Warning: This does not save a backup of your files, so make sure you've got a backup in case you need to revert the changes.