Skip to content

feat: let a minimizer in minify state its own filter - #729

Merged
alexander-akait merged 1 commit into
mainfrom
feat/minify-filter
Sep 6, 2026
Merged

feat: let a minimizer in minify state its own filter#729
alexander-akait merged 1 commit into
mainfrom
feat/minify-filter

Conversation

@alexander-akait

Copy link
Copy Markdown
Member

Summary

A minimizer said which assets it wanted through a filter property on the function, so two entries of the same minimizer could not each carry one — the shape image-minimizer-webpack-plugin accepts as minimizer: [{ implementation, options, filter }, …], and the last thing from it that could not be written here. A descriptor's filter now 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: minify runs over emitted assets, so an image that becomes a data: URI is never reached by it, but a minimizer under generate reads 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. filter is 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: filter in the minify object and array docs, and a new "Images that never become files" section covering what minify cannot 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 main rather 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

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-bot

changeset-bot Bot commented Sep 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c853407

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
minimizer-webpack-plugin Minor

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

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.27%. Comparing base (b018da7) to head (c853407).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexander-akait
alexander-akait merged commit b6a612f into main Sep 6, 2026
31 checks passed
@alexander-akait
alexander-akait deleted the feat/minify-filter branch September 6, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant