feat: configure or exclude each asset type's minifier via optimization.minimize - #21663
Conversation
…n.minimize `optimization.minimize` also accepts an object keyed by asset type (`javascript`, `css`, `html`): `false` excludes a type from the built-in minimizer, an object configures what it may do beyond the always-applied transforms. First option: `css.convertLengthUnits`, handed to `.css` assets and the inline CSS in HTML alike.
…hrough it
Per-type values are `false | options` — enable-with-defaults is expressed by
omitting the key, like `splitChunks`. Normalization canonicalizes the `true`
shorthand into the object form, and the defaults fill each type, so the JS
minimizer's `{ compress: { passes: 2 } }` shows up in the resolved config and
is overridable (`minimize.javascript` is handed as-is to the minimizer).
🦋 Changeset detectedLatest commit: baa2fc1 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 |
|
Warning Review limit reached
Next review available in: 33 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Note
|
| Layer / File(s) | Summary |
|---|---|
Minimization contracts and normalization schemas/WebpackOptions.json, lib/config/normalization.js, lib/config/defaults.js, .changeset/062-optimization-minimize-by-type.md |
optimization.minimize accepts booleans or per-asset options. Normalization preserves omitted and disabled values and clones object configurations. |
Type-specific minimizer wiring lib/config/defaults.js, lib/css/cssMinify.js, lib/html/htmlMinify.js, test/configCases/html/minimize-css-options/webpack.config.js |
The minimizer independently enables JavaScript, CSS, and HTML. CSS options, including convertLengthUnits, reach standalone CSS and inline HTML CSS processing. HTML options reach HTML processing. |
HTML printing and whitespace handling lib/html/syntax.js, lib/util/SourceProcessor.js |
HTML printing supports collapseWhitespace. Whitespace runs collapse outside preformatted elements, and inline CSS receives per-print length-unit settings. |
Configuration and output validation test/Defaults.unittest.js, test/configCases/css/..., test/configCases/html/..., test/configCases/optimization/... |
Snapshots and configuration cases validate default options, type-specific minimization, JavaScript options, CSS unit conversion, inline HTML CSS handling, and HTML whitespace collapsing. |
Possibly related PRs
- webpack/webpack#21595: Both changes extend HTML processing and printing through
lib/html/syntax.jsandlib/util/SourceProcessor.js. - webpack/webpack#21649: Both changes modify HTML minification behavior and add related HTML minimization tests.
🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Linked Issues check | The changes add object-form minimization and collapseWhitespace, but omit the required removeAttributeQuotes and collapseBooleanAttributes support [#21537]. |
Implement removeAttributeQuotes and collapseBooleanAttributes in the schema, HTML printer, normalization, and tests, or update the linked issue scope. | |
| Out of Scope Changes check | The PR adds CSS and JavaScript-specific options and CSS length-unit conversion, which are outside the directly linked HTML-focused issue [#21537]. |
Move CSS and JavaScript minimizer features to separate issues or link issues that explicitly cover those requirements. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title uses the valid feat conventional-commit type and clearly describes per-asset minifier configuration. |
Comment @coderabbitai help to get the list of available commands.
|
This PR is packaged and the instant preview is available (5a8fa6c). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@5a8fa6c
yarn add -D webpack@https://pkg.pr.new/webpack@5a8fa6c
pnpm add -D webpack@https://pkg.pr.new/webpack@5a8fa6c |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21663 +/- ##
=======================================
Coverage 94.50% 94.51%
=======================================
Files 630 630
Lines 81830 81889 +59
Branches 24204 24231 +27
=======================================
+ Hits 77337 77398 +61
+ Misses 4493 4491 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Generated code sizeComparing
17 asset(s) changed size
4 runtime(s) changed which runtime modules they carry
Built |
|
Caution CodeRabbit couldn't update its existing comment. The review summary may be out of date. Error details |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (3)
lib/html/htmlMinify.js (2)
55-57: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten the new explanatory comments.
lib/html/htmlMinify.js#L55-L57: reduce this comment to no more than two short lines.lib/html/htmlMinify.js#L62-L64: reduce this comment to no more than two short lines.lib/html/syntax.js#L8553-L8555: reduce this comment to no more than two short lines.As per coding guidelines, comments must be “generally one line and no more than two short lines.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/html/htmlMinify.js` around lines 55 - 57, Shorten the explanatory comments at lib/html/htmlMinify.js lines 55-57 and 62-64, and lib/html/syntax.js lines 8553-8555, to no more than two short lines each while preserving their essential meaning.Sources: Coding guidelines, Path instructions
26-26: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse the precise
minimizerOptionstype.The exact option shape is known in Lines 58-61. Replace
objectwith{ environment?: CssEnvironment, convertLengthUnits?: boolean }and remove the redundant assertion.As per coding guidelines, prefer specific real JSDoc types when a precise type is available.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/html/htmlMinify.js` at line 26, Update the minimizerOptions JSDoc annotation above the relevant HTML minification function to use the precise optional shape `{ environment?: CssEnvironment, convertLengthUnits?: boolean }` shown in the existing implementation, and remove the redundant assertion associated with the generic object type.Sources: Coding guidelines, Path instructions
lib/css/cssMinify.js (1)
34-37: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep the TODO within the source-comment limit.
The updated TODO uses four lines and includes detailed rationale. Keep the TODO to one or two short lines. Move the rationale to issue or documentation text.
Proposed edit
- // TODO expose the remaining declined transforms on `optimization.minimize.css` - // (the way `convertLengthUnits` already is), each off by default. Every one is - // something csso, cssnano, lightningcss or esbuild ships on, and every one - // costs something a build may not want to pay: + // TODO expose the remaining declined transforms in `optimization.minimize.css`.As per coding guidelines and path instructions, comments in
lib/**must be at most two short lines and add non-obvious information.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/css/cssMinify.js` around lines 34 - 37, Shorten the TODO in the CSS minification configuration near convertLengthUnits to one or two concise lines describing only the remaining declined transforms; remove the detailed rationale from the source comment and leave it for issue or documentation text.Sources: Coding guidelines, Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.changeset/062-optimization-minimize-by-type.md:
- Line 5: Shorten the changeset sentence to a single concise imperative
statement under 80 characters, preserving the instruction to configure or
exclude asset-type minifiers through optimization.minimize.
In `@lib/config/defaults.js`:
- Around line 2531-2536: Update the HTML minimizer branch around minify and
minimizerOptions to pass the HTML-specific optimization.minimize.html options
through htmlMinify into SourceProcessor.process, while retaining cssOptions for
inline styles. Add an output snapshot covering an HTML-only setting such as
removeAttributeQuotes to verify it affects generated output.
- Around line 2435-2437: Shorten the comments at lib/config/defaults.js lines
2435-2437, 2465-2468, and 2511-2513, plus
test/configCases/html/minimize-css-options/webpack.config.js lines 29-31, so
each is no more than two short lines while preserving its meaning.
In `@schemas/WebpackOptions.json`:
- Around line 3705-3709: Extend the OptimizationMinimizeHtml schema to define
the supported HTML minifier controls, including removeAttributeQuotes and
collapseBooleanAttributes, while preserving strict validation for unknown
properties. Update the htmlMinify wiring to pass these HTML-specific options
through to HTML serialization rather than CSS options, and add output coverage
verifying each option’s enabled and disabled behavior.
---
Nitpick comments:
In `@lib/css/cssMinify.js`:
- Around line 34-37: Shorten the TODO in the CSS minification configuration near
convertLengthUnits to one or two concise lines describing only the remaining
declined transforms; remove the detailed rationale from the source comment and
leave it for issue or documentation text.
In `@lib/html/htmlMinify.js`:
- Around line 55-57: Shorten the explanatory comments at lib/html/htmlMinify.js
lines 55-57 and 62-64, and lib/html/syntax.js lines 8553-8555, to no more than
two short lines each while preserving their essential meaning.
- Line 26: Update the minimizerOptions JSDoc annotation above the relevant HTML
minification function to use the precise optional shape `{ environment?:
CssEnvironment, convertLengthUnits?: boolean }` shown in the existing
implementation, and remove the redundant assertion associated with the generic
object type.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: c17d8e5a-3c16-49a0-883f-d22d375667c1
⛔ Files ignored due to path filters (8)
declarations/WebpackOptions.d.tsis excluded by!declarations/**schemas/WebpackOptions.check.jsis excluded by!schemas/**/*.check.jstest/__snapshots__/Cli.basictest.js.snapis excluded by!**/*.snap,!test/**/__snapshots__/**test/configCases/css/minimize-convert-length-units/__snapshots__/ConfigCacheTest.snapis excluded by!**/*.snap,!test/**/__snapshots__/**test/configCases/css/minimize-convert-length-units/__snapshots__/ConfigTest.snapis excluded by!**/*.snap,!test/**/__snapshots__/**test/configCases/html/minimize-css-options/__snapshots__/ConfigCacheTest.snapis excluded by!**/*.snap,!test/**/__snapshots__/**test/configCases/html/minimize-css-options/__snapshots__/ConfigTest.snapis excluded by!**/*.snap,!test/**/__snapshots__/**types.d.tsis excluded by!types.d.ts
📒 Files selected for processing (37)
.changeset/062-optimization-minimize-by-type.mdlib/config/defaults.jslib/config/normalization.jslib/css/cssMinify.jslib/html/htmlMinify.jslib/html/syntax.jsschemas/WebpackOptions.jsontest/Defaults.unittest.jstest/configCases/css/minimize-convert-length-units/index.jstest/configCases/css/minimize-convert-length-units/style.csstest/configCases/css/minimize-convert-length-units/test.config.jstest/configCases/css/minimize-convert-length-units/webpack.config.jstest/configCases/html/minimize-css-options/index.jstest/configCases/html/minimize-css-options/page.htmltest/configCases/html/minimize-css-options/test.config.jstest/configCases/html/minimize-css-options/webpack.config.jstest/configCases/optimization/minimize-css-only/index.jstest/configCases/optimization/minimize-css-only/page.htmltest/configCases/optimization/minimize-css-only/style.csstest/configCases/optimization/minimize-css-only/test.config.jstest/configCases/optimization/minimize-css-only/webpack.config.jstest/configCases/optimization/minimize-html-only/index.jstest/configCases/optimization/minimize-html-only/page.htmltest/configCases/optimization/minimize-html-only/style.csstest/configCases/optimization/minimize-html-only/test.config.jstest/configCases/optimization/minimize-html-only/webpack.config.jstest/configCases/optimization/minimize-javascript-only/index.jstest/configCases/optimization/minimize-javascript-only/page.htmltest/configCases/optimization/minimize-javascript-only/style.csstest/configCases/optimization/minimize-javascript-only/test.config.jstest/configCases/optimization/minimize-javascript-only/webpack.config.jstest/configCases/optimization/minimize-javascript-options/index.jstest/configCases/optimization/minimize-javascript-options/test.config.jstest/configCases/optimization/minimize-javascript-options/webpack.config.jstest/configCases/optimization/minimize-nothing/index.jstest/configCases/optimization/minimize-nothing/test.config.jstest/configCases/optimization/minimize-nothing/webpack.config.js
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
webpack/schema-utils(auto-detected)webpack/tapable(auto-detected)
| "OptimizationMinimizeHtml": { | ||
| "description": "What the HTML minimizer may do beyond the transforms that always apply. No additional options are supported yet.", | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "added": "5.110.0" |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Implement the required HTML minifier options.
OptimizationMinimizeHtml accepts only {}. The schema rejects HTML controls such as removeAttributeQuotes and collapseBooleanAttributes. The current minimizer wiring passes CSS options to htmlMinify, but it does not provide HTML-specific controls. Add the schema properties, propagate them to HTML serialization, and add output tests for enabled and disabled behavior.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@schemas/WebpackOptions.json` around lines 3705 - 3709, Extend the
OptimizationMinimizeHtml schema to define the supported HTML minifier controls,
including removeAttributeQuotes and collapseBooleanAttributes, while preserving
strict validation for unknown properties. Update the htmlMinify wiring to pass
these HTML-specific options through to HTML serialization rather than CSS
options, and add output coverage verifying each option’s enabled and disabled
behavior.
Merging this PR will degrade performance by 7.3%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | benchmark "wasm-modules-sync", scenario '{"name":"mode-development","mode":"development"}' |
1.1 s | 1.5 s | -26.83% |
| ❌ | Memory | benchmark "cache-filesystem", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
862.1 KB | 1,151.8 KB | -25.15% |
| ⚡ | Memory | benchmark "asset-modules-bytes", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1,143.2 KB | 786 KB | +45.45% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing feat/optimization-minimize-by-type (baa2fc1) with main (78d0d4c)
The first HTML-specific minimizer option, wired through the per-type map: each run of text whitespace collapses to one space — never removed outright — skipping `pre` / `textarea` / `listing` ancestors and any text carrying a `<`, which stays on the source-passthrough path.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/html/syntax.js (1)
5558-5564: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten the new prose comments.
Keep each comment to two short lines or fewer.
lib/html/syntax.js#L5558-L5564: reduce the prose that explains whitespace preservation.lib/html/syntax.js#L9318-L9320: reduce the prose that explains preformatted-element handling.As per coding guidelines and path instructions, “Comments must be at most two short lines and add non-obvious information.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/html/syntax.js` around lines 5558 - 5564, Shorten the comments in lib/html/syntax.js at lines 5558-5564 and 9318-9320 to no more than two short lines each, retaining only the non-obvious guidance about whitespace preservation and preformatted-element handling.Sources: Coding guidelines, Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/html/syntax.js`:
- Around line 5558-5564: Shorten the comments in lib/html/syntax.js at lines
5558-5564 and 9318-9320 to no more than two short lines each, retaining only the
non-obvious guidance about whitespace preservation and preformatted-element
handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 99ee556e-fcc9-4646-8919-d319a5c2b030
⛔ Files ignored due to path filters (6)
declarations/WebpackOptions.d.tsis excluded by!declarations/**schemas/WebpackOptions.check.jsis excluded by!schemas/**/*.check.jstest/__snapshots__/Cli.basictest.js.snapis excluded by!**/*.snap,!test/**/__snapshots__/**test/configCases/html/minimize-collapse-whitespace/__snapshots__/ConfigCacheTest.snapis excluded by!**/*.snap,!test/**/__snapshots__/**test/configCases/html/minimize-collapse-whitespace/__snapshots__/ConfigTest.snapis excluded by!**/*.snap,!test/**/__snapshots__/**types.d.tsis excluded by!types.d.ts
📒 Files selected for processing (9)
lib/config/defaults.jslib/html/htmlMinify.jslib/html/syntax.jslib/util/SourceProcessor.jsschemas/WebpackOptions.jsontest/configCases/html/minimize-collapse-whitespace/index.jstest/configCases/html/minimize-collapse-whitespace/page.htmltest/configCases/html/minimize-collapse-whitespace/test.config.jstest/configCases/html/minimize-collapse-whitespace/webpack.config.js
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
webpack/schema-utils(auto-detected)webpack/tapable(auto-detected)
🚧 Files skipped from review as they are similar to previous changes (3)
- schemas/WebpackOptions.json
- lib/config/defaults.js
- lib/html/htmlMinify.js
Prettier's first pass over two untouched regions was not a fixed point; the committed form now matches what `--check` verifies.
The config case exercises it only inside the minimizer's worker pool, which jest's coverage cannot see — the same reason the CSS `convertLengthUnits` transforms are unit-tested directly.
Summary
optimization.minimizealso accepts a per-asset-type object (javascript/css/html):falsedisables minimizing that type, an object configures it —css.convertLengthUnitsis the first option, forwarded to.cssassets and the inline CSS in HTML alike, andjavascriptis handed as-is to the JS minimizer, with its{ compress: { passes: 2 } }default now visible in the resolved config. Normalization canonicalizes thetrueshorthand into the object form, so this generalizes the single-type approach proposed earlier. Closes #21537.What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes —
configCases/css/minimize-convert-length-units,configCases/html/minimize-css-options, andconfigCases/optimization/minimize-{css-only,html-only,javascript-only,javascript-options,nothing}, all passing underConfigTestCasesandConfigCacheTestCases.Does this PR introduce a breaking change?
No —
minimize: true/falsekeep their behavior; the object form is new.If relevant, what needs to be documented once your changes are merged or what have you already documented?
The
optimization.minimizeobject form: per-typefalse,css.convertLengthUnits, and thejavascriptminimizer options with their default.Use of AI
Implemented with Claude Code under my direction: it wrote the schema/config wiring and tests per my design decisions, and I reviewed the changes.
Generated by Claude Code
Summary by CodeRabbit
New Features
Bug Fixes