{"id":15839,"library":"squeezit","title":"Squeezit Image Optimizer","description":"Squeezit (current stable version 1.17.0) is a versatile, lossless-first image optimization utility offered as a command-line interface (CLI), a JavaScript/TypeScript API, and a comprehensive suite of bundler plugins. It targets a wide array of modern and legacy image formats including PNG, JPEG, GIF, WebP, SVG, AVIF, HEIC, JXL, ICO, and BMP, focusing on reducing file sizes without noticeable degradation. The project exhibits active development, frequently integrating with contemporary build tools. Its key differentiators include broad format support, a user-friendly CLI with clear output, robust pattern matching for file selection (supporting shell-style and glob expressions), and a safe, threshold-based replacement mechanism to prevent unnecessary file churn. Squeezit integrates directly with ecosystems like Gulp, Grunt, Vite, Webpack, Rollup, Parcel, Astro, Next.js, esbuild, and Babel, making it suitable for a diverse range of development workflows and CI/CD pipelines.","status":"active","version":"1.17.0","language":"javascript","source_language":"en","source_url":"https://github.com/ghaschel/squeeze","tags":["javascript","squeezit","image","images","image-compression","image-optimizer","image-optimization","lossless","lossless-compression","typescript"],"install":[{"cmd":"npm install squeezit","lang":"bash","label":"npm"},{"cmd":"yarn add squeezit","lang":"bash","label":"yarn"},{"cmd":"pnpm add squeezit","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for the Babel plugin integration. Must be installed separately if using the plugin.","package":"@babel/core","optional":true},{"reason":"Peer dependency for the esbuild plugin integration. Must be installed separately if using the plugin.","package":"esbuild","optional":true},{"reason":"Peer dependency for the Gulp plugin integration. Must be installed separately if using the plugin.","package":"gulp","optional":true},{"reason":"Peer dependency for the Grunt plugin integration. Must be installed separately if using the plugin.","package":"grunt","optional":true},{"reason":"Peer dependency for the Next.js wrapper integration. Must be installed separately if using the wrapper.","package":"next","optional":true},{"reason":"Peer dependency for the Astro wrapper integration. Must be installed separately if using the wrapper.","package":"astro","optional":true},{"reason":"Engine and peer dependency for the Parcel optimizer plugin integration. Must be installed separately if using the plugin.","package":"parcel","optional":true},{"reason":"Peer dependency for the Rollup plugin integration. Must be installed separately if using the plugin.","package":"rollup","optional":true},{"reason":"Peer dependency, especially relevant for TypeScript projects using the API or plugins. Must be installed separately.","package":"typescript","optional":true},{"reason":"Peer dependency for the Vite plugin integration. Must be installed separately if using the plugin.","package":"vite","optional":true},{"reason":"Peer dependency for the Webpack plugin integration. Must be installed separately if using the plugin.","package":"webpack","optional":true}],"imports":[{"note":"The primary API functions are ESM-first. While CJS might work via transpilation, direct require is not the idiomatic usage.","wrong":"const { optimizeFile } = require('squeezit')","symbol":"optimizeFile","correct":"import { optimizeFile } from 'squeezit'"},{"note":"Gulp plugin is a named export from its specific subpath.","wrong":"import squeezitGulp from 'squeezit/gulp'","symbol":"squeezitGulp","correct":"import { squeezitGulp } from 'squeezit/gulp'"},{"note":"The Grunt plugin is designed for CommonJS `require` due to typical Gruntfile environments.","wrong":"import { registerSqueezitTask } from 'squeezit/grunt'","symbol":"registerSqueezitTask","correct":"const { registerSqueezitTask } = require('squeezit/grunt')"},{"note":"Vite plugin is a named ESM export.","wrong":"const { squeezitVite } = require('squeezit/vite')","symbol":"squeezitVite","correct":"import { squeezitVite } from 'squeezit/vite'"}],"quickstart":{"code":"import { optimizeFile } from 'squeezit';\nimport { promises as fs } from 'fs';\nimport path from 'path';\n\nasync function runOptimization() {\n  const imagePath = path.join(process.cwd(), 'example.png');\n  const outputPath = path.join(process.cwd(), 'optimized-example.png');\n\n  // Create a dummy image file for demonstration if it doesn't exist\n  try {\n    await fs.access(imagePath);\n  } catch (error) {\n    console.log(`Creating dummy file at ${imagePath}`);\n    // Minimal PNG base64 representation (1x1 transparent PNG)\n    const dummyPngBuffer = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=', 'base64');\n    await fs.writeFile(imagePath, dummyPngBuffer);\n  }\n\n  console.log(`Optimizing ${imagePath}...`);\n  const result = await optimizeFile(imagePath, { \n    output: outputPath,\n    overwrite: true, // Overwrite if target path is the same\n    dryRun: false // Set to true to preview without saving\n  });\n\n  if (result.success) {\n    console.log(`Optimization successful:`);\n    console.log(`  Original size: ${result.originalSize} bytes`);\n    console.log(`  Optimized size: ${result.optimizedSize} bytes`);\n    console.log(`  Reduction: ${((1 - result.optimizedSize / result.originalSize) * 100).toFixed(2)}%`);\n    console.log(`  Output to: ${outputPath}`);\n  } else {\n    console.error(`Optimization failed: ${result.error}`);\n  }\n\n  // Clean up the dummy file\n  await fs.unlink(imagePath);\n  if (result.success) {\n    await fs.unlink(outputPath);\n  }\n}\n\nrunOptimization().catch(console.error);","lang":"typescript","description":"Demonstrates programmatic image optimization using the core `optimizeFile` API, creating a temporary file and reporting optimization results."},"warnings":[{"fix":"Manually install the required peer dependencies using your package manager (e.g., `npm install webpack` or `yarn add gulp`) ensuring version compatibility as specified in Squeezit's `peerDependencies`.","message":"When using Squeezit's bundler plugins (e.g., for Webpack, Vite, Gulp), their respective peer dependencies (e.g., 'webpack', 'vite', 'gulp') must be installed separately in your project. Failure to do so, or using incompatible versions, will result in runtime errors. Squeezit will not install these automatically.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer local installation (`npm install squeezit`) and run via `npx squeezit` in projects to ensure correct versioning, or use a version manager like `fnm` or `nvm` for global installations.","message":"The `squeezit` CLI is often installed globally (`npm install -g squeezit`). While convenient, ensure the global version aligns with any local project dependencies or specific plugin requirements to avoid unexpected behavior or command failures due to version mismatches.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Review the optimization goals. If aggressive lossy compression is needed, integrate a separate lossy optimization step or tool into your workflow before or after Squeezit, or explore Squeezit's options for near-lossless modes if available.","message":"Squeezit emphasizes a 'lossless-first' approach. While it provides aggressive compression, users expecting significant file size reductions that typically come with lossy compression might find the results less dramatic than anticipated. For maximum reduction, additional lossy steps might be required.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `squeezit -r \"your/glob/**/*.pattern\"` when you intend to optimize images within nested folders.","message":"When using glob expressions (e.g., `images/**/*.jpg`) with the CLI, recursive scanning is not enabled by default. You must explicitly include the `-r` or `--recursive` flag for Squeezit to process files in subdirectories.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Install globally with `npm install -g squeezit` or `bun add -g squeezit`. Alternatively, if installed locally, run with `npx squeezit`.","cause":"The `squeezit` CLI tool is not installed globally or is not in your system's PATH.","error":"command not found: squeezit"},{"fix":"Install the missing peer dependency: `npm install webpack` (or `vite`, `gulp`, etc., depending on the plugin in use).","cause":"A Squeezit bundler plugin (e.g., Webpack, Vite, Gulp) was used without its corresponding peer dependency installed in the project.","error":"Error: Cannot find module 'webpack' from 'squeezit/webpack'"},{"fix":"Check the detailed error message for clues. Verify the image file's integrity and ensure it's a supported format. Consider reporting the issue to the Squeezit project with the full error and file details.","cause":"An unexpected issue occurred during the image optimization process, potentially due to a corrupted file, unsupported image format variant, or an internal library error.","error":"Error: Image processing failed for file 'path/to/image.png': [detailed error message]"}],"ecosystem":"npm"}