Skip to content

fix: minify assets whose names carry a fragment - #747

Merged
alexander-akait merged 4 commits into
mainfrom
fix/fragment-asset-names
Sep 24, 2026
Merged

alexander-akait merged 4 commits into
mainfrom
fix/fragment-asset-names

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

webpack keeps a #fragment in asset names (asset modules default to [hash][ext][query][fragment], and output.filename may contain #), but every built-in filter, the default test, the .mjs/.cjs detection and extensionOf accepted only a ? query, so e.g. main.js#abc passed test and was then skipped. The extension is now read from before the first ? or #, which also stops data.txt#a.css being claimed as CSS. Companion to webpack/webpack#22277.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes — test/test-option.test.js (JS/MJS/JSON builds with fragment names, plus every built-in filter) and test/css-minify-option.test.js (CSS/HTML builds); both fail without the fix.

Does this PR introduce a breaking change?

No.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

n/a

Use of AI

Written with Claude Code: it reproduced the bug in a real webpack build, made the change and wrote the tests; the result was reviewed and directed by the author.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EpeANYvMKyZwSDTRVE5LoG


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Assets with URL fragments in their names are correctly recognized and minified, including JavaScript, CSS, HTML, and JSON files.
    • Built-in minifier filters correctly identify supported file types in fragment-bearing filenames. JavaScript module assets with fragments use the appropriate module setting for .mjs and .cjs files.
    • Extracted license files are named correctly when the original asset includes a fragment, with or without a query string.

webpack keeps a `#fragment` in the asset name (`[hash][ext][query][fragment]`
for asset modules, or a `#` in `output.filename`) and strips it only when
writing. `test` already fell back to the bare name, but every built-in
`filter`, the default `test`, the `.mjs`/`.cjs` detection and `extensionOf`
accepted a query only, so such assets were skipped. Read the extension from
before the first `?` or `#`.

Claude-Session: https://claude.ai/code/session_01EpeANYvMKyZwSDTRVE5LoG
@changeset-bot

changeset-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 65b91f2

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 Patch

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 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.86%. Comparing base (c8c4bf2) to head (65b91f2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #747      +/-   ##
==========================================
+ Coverage   97.79%   97.86%   +0.06%     
==========================================
  Files           5        5              
  Lines        1634     1637       +3     
  Branches      620      622       +2     
==========================================
+ Hits         1598     1602       +4     
+ Misses         36       35       -1     

☔ 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.

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: b5babc2e-3429-4f54-b346-7f51e2484789

📥 Commits

Reviewing files that changed from the base of the PR and between ff50d2f and 65b91f2.

📒 Files selected for processing (2)
  • src/index.js
  • test/extractComments-option.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/index.js

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.


Walkthrough

The plugin now recognizes file extensions followed by either a query or a fragment. Its extension helper removes both suffix types before deriving the extension. Extracted-comment filename parsing strips fragments while preserving query suffixes. Tests cover fragment-bearing assets and built-in minifier filters.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 65b91

Fragment-bearing assets are matched by their extensions, and extracted license filenames remain separate from JavaScript assets. No concrete merge risk remains in the reviewed changes.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing minification for assets whose names contain a fragment.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 7 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/index.js

ESLint failed to execute (timeout).

test/extractComments-option.test.js

ESLint skipped: the matched ESLint configuration already failed (timeout).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Remove the fragment before building the extracted-comments filename. · index.js:1113-1118

src/index.js:1113-1118
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Remove the fragment before building the extracted-comments filename.

When a newly eligible asset is named main.js#abc, this code passes main.js#abc as filename to an extractComments.filename callback. A callback that returns ${fileData.filename}.LICENSE.txt produces main.js#abc.LICENSE.txt. Webpack removes fragments when writing assets, so that license asset and the JavaScript asset target main.js on disk. Split the filename at the first ? or #, and keep only a preceding query in query. The documented callback uses fileData.filename in this way. (webpack.js.org)


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 7742aace-7b35-4361-b592-53cf92c14133

📥 Commits

Reviewing files that changed from the base of the PR and between c8c4bf2 and 9c21eb8.

📒 Files selected for processing (7)
  • .changeset/fragment-asset-names.md
  • src/index.js
  • src/utils.js
  • test/css-minify-option.test.js
  • test/fixtures/fragment-assets.js
  • test/helpers/readAsset.js
  • test/test-option.test.js

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread test/test-option.test.js
A function `extractComments.filename` built `main.js#abc.LICENSE.txt` from
`fileData.filename`, which webpack writes onto `main.js` itself. Split the
name at the first `?` or `#`; only a query is handed on as `query`.

Claude-Session: https://claude.ai/code/session_01EpeANYvMKyZwSDTRVE5LoG

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 3097cb68-4826-4357-8288-1416bc663aca

📥 Commits

Reviewing files that changed from the base of the PR and between 9c21eb8 and ff50d2f.

📒 Files selected for processing (3)
  • src/index.js
  • test/extractComments-option.test.js
  • test/test-option.test.js

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Comment thread src/index.js Outdated
@alexander-akait
alexander-akait merged commit 55cadc3 into main Sep 24, 2026
31 checks passed
@alexander-akait
alexander-akait deleted the fix/fragment-asset-names branch September 24, 2026 11:20
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