I got tired of checking for unused images as they piled up, so I built a CLI tool to detect and get rid of them.
A CLI tool to detect and remove unused images in your project.
demo.mp4
Important: Only use this tool inside your own project repositories. Do not run this on system folders, external drives, or outside of your intended project — it may detect and delete images based on filename matches.
# Scan a specific folder (relative to the current working directory) and print unused images without deleting anything
npx purge-img src/assets
# Actually remove unused images
npx purge-img src/assets -r
# Ignore specific patterns
npx purge-img src/assets -i "**/*.test.tsx"
# Show help
npx purge-img --help.js,.jsx,.ts,.tsx,.html,.css,.scss,.vue,.svelte,.md,.mdx,.json,.yaml,.yml,.txt
.png,.jpg,.jpeg,.svg,.gif,.webp,.avif,.apng
- Scans the specified assets folder for all supported image files
- Scans the project for source files with supported extensions
- Checks if the image file basename is used in the supported source files (e.g.,
file.png) - Returns a list of unused images
You can use the -i or --ignore flag to specify patterns to ignore. You can specify multiple patterns by using the flag multiple times.
npx purge-img src/assets -i "**/*.test.tsx"You can also create an .purgeimgignore file in the root of your project to specify patterns to ignore.
# .purgeimgignore
**/*.test.tsx- It doesn't differentiate files with the same name from different folders
MIT