feat: let a minimizer in minify state its own filter - #729
Merged
Conversation
A minimizer said which assets it wanted through a `filter` property on the
function, so two entries of the same minimizer could not each have one —
the pattern `image-minimizer-webpack-plugin` wrote as
`minimizer: [{ implementation, options, filter }, …]`. A descriptor's
`filter` answers for that entry and falls back to the function's own.
Documents, with it, what `minify` cannot reach: an image that becomes a
`data:` URI is never an emitted asset, so a raster inline is minified by
`generate` — which runs over the module's bytes — rather than here. Only
a language written as text is offered as embedded source, which is why an
inline SVG is the exception.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016TQeNpahUSDUjD2Crugy5H
🦋 Changeset detectedLatest commit: c853407 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #729 +/- ##
==========================================
+ Coverage 95.24% 95.27% +0.02%
==========================================
Files 4 4
Lines 1347 1354 +7
Branches 492 503 +11
==========================================
+ Hits 1283 1290 +7
Misses 56 56
Partials 8 8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
A minimizer said which assets it wanted through a
filterproperty on the function, so two entries of the same minimizer could not each carry one — the shapeimage-minimizer-webpack-pluginaccepts asminimizer: [{ implementation, options, filter }, …], and the last thing from it that could not be written here. A descriptor'sfilternow answers for that entry and falls back to the property on the function, so the built-ins' own filters keep dispatching as before.Found while auditing what the old plugin had that this one lacks. The audit's other finding turned out to be a documentation gap rather than a missing capability:
minifyruns over emitted assets, so an image that becomes adata:URI is never reached by it, but a minimizer undergeneratereads the module's bytes before anything encodes them and does minify one. Only a language written as text is offered as embedded source (languageOfMediaType), which is why an inline SVG is minified and an inline JPEG is not. That is now written down, with the config that works and a warning against listing the same image minimizer in both places, which would re-encode an emitted asset twice.What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes — four in
test/minify-option.test.js: a descriptor's filter deciding what one minimizer is offered, the same minimizer configured twice with a filter and options each, a descriptor's filter answering for one on the function, and the fallback to the function's own. Three of them fail with the dispatch change reverted.Does this PR introduce a breaking change?
No.
filteris new and optional, and a minimizer that carries the property keeps being dispatched by it.If relevant, what needs to be documented once your changes are merged or what have you already documented?
Both are in this PR:
filterin theminifyobject and array docs, and a new "Images that never become files" section covering whatminifycannot reach.Use of AI
Claude Code wrote the change, the tests and the docs; I reviewed them before submitting. The inline-image behaviour was checked by building a fixture against webpack
mainrather than reasoned about — that experiment is what turned a suspected missing feature into a documentation fix, and stopped a proposed webpack core change that was not needed.🤖 Generated with Claude Code
https://claude.ai/code/session_016TQeNpahUSDUjD2Crugy5H
Generated by Claude Code