Visitar URL original
docs: how to use webpack's own css and html minimizers by alexander-akait · Pull Request #718 · webpack/minimizer-webpack-plugin · GitHub
Skip to content

docs: how to use webpack's own css and html minimizers - #718

Merged
alexander-akait merged 4 commits into
mainfrom
docs/webpack-builtin-minimizers
Sep 4, 2026
Merged

alexander-akait merged 4 commits into
mainfrom
docs/webpack-builtin-minimizers

Conversation

@alexander-akait

Copy link
Copy Markdown
Member

Summary

The README names webpack's own cssMinify and htmlMinify twice under Embedded source but never shows how to import or configure them, so the section explaining that they are the two minimizers able to hand out nested bodies had no worked example to point at. Adds a webpack's own minimizers section — import paths, a config using them alongside terserMinify and jsonMinify, what each declares (getTypes / getEmbeddedTypes / filter / supportsWorkerThreads), where environment goes, and the two ways it goes wrong: passing renderEmbeddedSource yourself (the plugin owns that option and replaces it) and a second or older copy of webpack in the tree, whose error message is quoted so it is searchable. Also lists them in the existing CSS and HTML minimizer lists.

Every snippet was executed against a real build rather than written from the types: two corrections came out of that, environment being top level on htmlMinify rather than nested under css, and CssEnvironment being { browsers, vendorPrefixes }.

What kind of change does this PR introduce?

docs

Did you add tests for your changes?

No — documentation only, no source change. The configurations shown were run against a real webpack build to confirm they work.

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?

This is the documentation. Nothing further is needed after merge.

Use of AI

Claude Code drafted the section and verified it by running every configuration in it against a real build instead of transcribing the JSDoc, which is how the two option-shape errors above were caught before they shipped. The require("webpack") failure mode documented at the end was likewise found by hitting it, not by reading the code.


Generated by Claude Code

They ship with webpack and need no extra dependency, and they are the two
that can hand out what a document or a stylesheet nests inside itself, so
what the README already says about embedded source had no worked example
to point at. Name them in the css and html minimizer lists and add a
section: the import paths, a config using them alongside terser and json,
what each declares, where `environment` goes, and the two ways it goes
wrong -- passing `renderEmbeddedSource` (the plugin owns it) and a second
copy of webpack in the tree, whose error message is quoted.
@changeset-bot

changeset-bot Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 0a413e7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codecov

codecov Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.73%. Comparing base (5ab38cb) to head (0a413e7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #718   +/-   ##
=======================================
  Coverage   94.73%   94.73%           
=======================================
  Files           4        4           
  Lines        1102     1102           
  Branches      392      392           
=======================================
  Hits         1044     1044           
  Misses         51       51           
  Partials        7        7           

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

eslint lints the code blocks in the README, and the example was a
fragment -- a labelled statement with a trailing comma -- so `lint:code`
rejected it. Bind it to a name instead; the config it shows is unchanged.
`cssMinify` and `htmlMinify` are not on webpack's public surface today --
they are absent from `lib/index.js` and from `types.d.ts`, so the section
documented a deep require into `webpack/lib/`. They are being exported on
`webpack.css.syntax` and `webpack.html.syntax` instead, which is where the
parser they already read at run time lives, so point the docs there and
state the release that carries them.
The section named `environment` and then waved at "the rest". Tabulate
what each minifier actually accepts, read off the two functions rather
than their JSDoc: the top-level options with types and defaults, and the
per-transform switches, which sit beside the rest rather than nested
because `pickTransforms` is handed the whole options object.

State what `css` takes on `htmlMinify`, since it is a subset plus the CSS
switches, and `environment` is deliberately not in it.
@alexander-akait
alexander-akait merged commit 4f65acd into main Sep 4, 2026
31 checks passed
@alexander-akait
alexander-akait deleted the docs/webpack-builtin-minimizers branch September 4, 2026 12:08
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