You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add cwebp task for converting images to WebP format - #7690
Implemented 'cwebp' Grunt task to convert images to WebP format. Updated 'precommit:image' task to include 'cwebp:dynamic' ensuring WebP conversion during pre-commit.
Implemented 'cwebp' Grunt task to convert images to WebP format. Updated 'precommit:image' task to include 'cwebp:dynamic' ensuring WebP conversion during pre-commit.
The changes in this pull request can previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.
Some things to be aware of
The Plugin and Theme Directories cannot be accessed within Playground.
All changes will be lost when closing a tab with a Playground instance.
All changes will be lost when refreshing the page.
A fresh instance is created each time the link below is clicked.
Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.
I agree with the image quality likely being far too low. It seems Core uses 86as the default for WebP. I think matching that is a good start.
Were there specific reasons for choosing grunt-cwebp over some of the other available options, such as Ayesh/grunt-webp? The former has not been updated in 4 years, but the latter was updated 2 years ago and @Ayesh is an active member of the community, so it may be easier to get any needed updates released.
There's also some additional options such as lossless, and deleteLarger in Ayesh/grunt-webp. I wonder if configuring these would be beneficial as well.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The WebP task uses glob patterns that match no files, writes output to a literal SOURCE_DIR/ directory, and is not triggered by WebP-only changes during pre-commit.
The reason will be displayed to describe this comment to others. Learn more.
dest: 'SOURCE_DIR' is a literal directory name, rather than the configured source directory. Please correct the output mapping and verify the intended behavior on a second precommit:image run: the current inputs are already WebP files, so repeated lossy re-encoding needs to be avoided. The Grunt and package changes also need refreshing against trunk.
Updated glob patterns for webp images and fixed destination path.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The precommit image target repeatedly overwrites existing WebPs with lossy re-encodings, causing cumulative quality loss and unrelated asset changes even when only a PNG is edited.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Avoid cumulative lossy re-encoding of existing WebP assets
Gruntfile.js:1047
q: 80 performs lossy re-encoding, but this target reads existing WebP files and writes back to the same paths. Because precommit:image runs this target for any image change, even an unrelated PNG edit re-encodes all existing theme WebPs; subsequent runs use the previously compressed output, causing cumulative quality loss and unrelated asset changes. Please use lossless optimization for existing WebPs, or generate lossy outputs from preserved original sources instead of overwriting and reusing them.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for refreshing this. It's not ready yet:
Every CI job fails at npm ci.package.json adds grunt-contrib-imagemin, which r63784 removed, while package-lock.json adds grunt-cwebp. The two files are out of sync ("Missing: grunt-contrib-imagemin@4.0.0 from lock file").
The cwebp task never runs.precommit:image still lists only imagemin:core, though the PR description says it adds cwebp:dynamic. And since grunt-cwebp isn't in package.json, the loadNpmTasks loop never loads it.
Adding webp to the precommit check runs imagemin:core, which only handles PNG, JPEG and GIF.
Wired up, it would degrade the images. It re-encodes the existing .webp files in place at quality 80, so every run loses more quality. I raised this on Oct 31.
There's a simpler path now. r63784 replaced grunt-contrib-imagemin with a local task, tools/imagemin/task.js, built on @napi-rs/image. That library already has Transformer#webpLosslessSync(). Adding WebP to that task would keep the output lossless and reuse its 64-byte threshold to skip trivial rewrites. It also avoids a new dependency: grunt-cwebp was last published in 2022, and cwebp-bin runs an install script to fetch the binary. Would you be up for reworking it that way?
AI review · claude-opus-5-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implemented 'cwebp' Grunt task to convert images to WebP format. Updated 'precommit:image' task to include 'cwebp:dynamic' ensuring WebP conversion during pre-commit.
Trac ticket: https://core.trac.wordpress.org/ticket/62188