Skip to content

feat(html): allow object for optimization.minimize to support HTML minification options - #21537

Closed
aryanraj45 wants to merge 1 commit into
webpack:mainfrom
aryanraj45:feat/html-minimize-options
Closed

aryanraj45 wants to merge 1 commit into
webpack:mainfrom
aryanraj45:feat/html-minimize-options

Conversation

@aryanraj45

@aryanraj45 aryanraj45 commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Extends HTML minification to optionally strip quotes from attributes and collapse boolean attributes when optimization.minimize is configured as an options object.

This builds on the safe minify groundwork introduced in #21491. While #21491 establishes the HTML/CSS minimizers, this PR updates the Webpack schema to allow optimization.minimize to be an object instead of just a boolean. This enables passing specific options down to the minimizers, and specifically implements removeAttributeQuotes and collapseBooleanAttributes in the HTML printer (lib/html/syntax.js).

What kind of change does this PR introduce?

feat

Did you add tests for your changes?

Yes, added ConfigTestCases for html minimize covering the new schema object shape and attribute output.

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?

The new optimization.minimize object options (removeAttributeQuotes and collapseBooleanAttributes) should be documented.

Use of AI

YES


Note

Medium Risk
Opt-in HTML output changes can affect layout if whitespace is relied on outside excluded elements; wiring is limited to production minify defaults but touches emitted .html assets.

Overview
optimization.minimize can be an object (still accepts a boolean). An object turns minimization on and passes per-minimizer options beyond the always-safe transforms; the first supported knob is html.collapseWhitespace, typed as OptimizationMinimizeHtml in the public declarations and JSON schema.

When HTML minification runs, lib/config/defaults.js spreads optimization.minimize.html into the built-in HTML minifier options (alongside the existing CSS environment). htmlMinify forwards collapseWhitespace into the HTML SourceProcessor, which implements optional text-node collapsing via a new collapseWs helper: runs of HTML whitespace become a single space, never removed entirely, skipped under pre / textarea / listing ancestors, and skipped when text contains < so template-like content stays on the passthrough path.

Reviewed by Cursor Bugbot for commit 7606cb0. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7606cb0

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

This PR includes changesets to release 1 package
Name Type
webpack 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

@aryanraj45
aryanraj45 force-pushed the feat/html-minimize-options branch from 48f9510 to 6d7c6f5 Compare July 30, 2026 21:51
@aryanraj45
aryanraj45 marked this pull request as ready for review July 30, 2026 21:51
Comment thread lib/html/syntax.js Resolved
Comment thread lib/html/syntax.js Resolved

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f9b60f3. Configure here.

Comment thread lib/html/syntax.js Resolved
Carries what a minimizer may do beyond the transforms that always apply,
starting with html.collapseWhitespace: each run of whitespace in text
becomes a single space, never nothing — removing it joins two inline
elements that render apart. Skipped under pre/textarea/listing and for
text holding a '<', which stays on the source-passthrough path.
@aryanraj45
aryanraj45 force-pushed the feat/html-minimize-options branch from f9b60f3 to 7606cb0 Compare August 7, 2026 15:05
@aryanraj45

aryanraj45 commented Aug 7, 2026 •

Copy link
Copy Markdown
Member Author

@alexander-akait optimization.minimizenow also takes an object, so there's a place for things a minimizer may do beyond the always-safe transforms. First one ishtml.collapseWhitespace`:

optimization: { minimize: { html: { collapseWhitespace: true } } }

A run of whitespace becomes a single space, never dropped — removing it would join two inline elements that render apart. Skipped under pre/textarea/listing, and for text with a < so <%= x %> isn't escaped. true/false unchanged

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