comp-2-webp
v1.0.1
Published
CLI tool to convert images to webp and update references in project files.
Readme
Compress2Webp (comp-2-webp)
A CLI tool to convert images to .webp format and update references in your project files.
Features
- Convert single images, folders, or glob patterns to
.webp(supports.png,.jpg,.jpeg,.svg, and optionally.webp) - Recursively process folders and subfolders
- Replace original images with
-rflag - Set compression percentage with
-pflag (default: 95) - Update all references to images in project files with
-uflag - Specify which file extensions to update with
-eflag - Show version with
-v - Show help with
-h
Installation & Usage
You can use it directly with npx or install globally:
npx comp-2-webp <input> [options]
# or
npm install -g comp-2-webp
comp-2-webp <input> [options]Arguments
<input>: Path to an image file, a folder, or a glob pattern (e.g.src/images/*.png)
Options
-r, --replace
Replace the original image with the.webpversion.-p, --percent <number>
Set webp compression percentage (default: 95).-u, --update
Update all references to the converted images in your project files.
Shows a list of files to be updated and allows you to skip any.-e, --ext <extensions>
Comma-separated list of file extensions to update (default:js,jsx,ts,tsx,html,css,py,json).-w, --webp
Also compress.webpfiles.-v, --version
Show the tool version.-h, --help
Show help.
Examples
Convert a single image:
comp-2-webp path/to/image.pngConvert all images in a folder (recursively):
comp-2-webp path/to/folderConvert all .png images in a folder:
comp-2-webp path/to/folder/*.pngConvert and replace originals:
comp-2-webp path/to/folder -rSet compression to 80%:
comp-2-webp path/to/folder -p 80Update all references in project files:
comp-2-webp path/to/folder -uUpdate references only in .js and .html files:
comp-2-webp path/to/folder -u -e js,htmlCompress .webp files as well:
comp-2-webp path/to/folder -wNotes
- When using
-u, the tool will show you all files that will be updated and allow you to skip any before proceeding. - Always backup your project or use version control before running with
-u!
License
MIT
