imagemin-lint-staged
raw JSON → 0.5.1 verified Fri May 01 auth: no javascript
A CLI wrapper around imagemin designed specifically for use with lint-staged (git pre-commit hooks). Version 0.5.1 is the latest stable release. It compresses PNG, JPEG, GIF, and SVG images automatically during staged file checks, with sensible default plugins (mozjpeg, optipng, svgo, gifsicle). Unlike using imagemin directly, it integrates seamlessly into lint-staged configurations without any configuration overhead. The package is lightweight (no peer dependencies) and runs synchronously to fit lint-staged's workflow.
Common errors
error Error: Cannot find module 'imagemin-lint-staged' ↓
cause imagemin-lint-staged is not installed or not in the same directory as the lint-staged config.
fix
Run 'npm install --save-dev imagemin-lint-staged' from the project root.
error imagemin-lint-staged: command not found ↓
cause imagemin-lint-staged is not in PATH; lint-staged runs scripts from node_modules/.bin, but if configured incorrectly, it may not find the binary.
fix
Ensure lint-staged is configured to run 'imagemin-lint-staged' as a string (not a function). The binary is provided via the package's bin field.
Warnings
gotcha imagemin-lint-staged will fail if any image file cannot be processed (e.g., corrupted file) and blocks the commit. ↓
fix Ensure image files are valid before committing, or add a fallback to skip compression on error.
gotcha The CLI does not accept custom imagemin options; it uses hardcoded default plugins (mozjpeg, optipng, svgo, gifsicle). ↓
fix If custom options are needed, use imagemin directly instead of this package.
Install
npm install imagemin-lint-staged yarn add imagemin-lint-staged pnpm add imagemin-lint-staged Imports
- default wrong
const imageminLintStaged = require('imagemin-lint-staged')correctimport imageminLintStaged from 'imagemin-lint-staged'
Quickstart
// package.json snippet for lint-staged
{
"lint-staged": {
"*.{png,jpeg,jpg,gif,svg}": ["imagemin-lint-staged"]
}
}
// Additionally, ensure imagemin-lint-staged is installed
npm install --save-dev imagemin-lint-staged lint-staged husky