feat: add built-in HTML minimizers from html-minimizer-webpack-plugin#668
Merged
alexander-akait merged 5 commits intomainfrom May 4, 2026
Merged
feat: add built-in HTML minimizers from html-minimizer-webpack-plugin#668alexander-akait merged 5 commits intomainfrom
alexander-akait merged 5 commits intomainfrom
Conversation
Move the HTML minifier implementations from `html-minimizer-webpack-plugin` into this plugin so HTML assets can be minified via the standard `TerserPlugin` interface. Adds four new static helpers: - `TerserPlugin.htmlMinifierTerser` (uses `html-minifier-terser`) - `TerserPlugin.swcMinifyHtml` (uses `@swc/html` for full documents) - `TerserPlugin.swcMinifyHtmlFragment` (uses `@swc/html` for fragments) - `TerserPlugin.minifyHtmlNode` (uses `@minify-html/node`) The HTML packages are declared as optional peer dependencies — install only the one you actually use. Documentation in the README now includes a dedicated HTML section with usage examples for each minimizer.
Replace the brief intro with a structured overview that groups every built-in minimizer (JS, JSON, HTML) under its asset type, names the static helper, links the upstream tool, and notes which optional peer dependency to install. This makes it easy to pick the right minimizer without reading the full Examples section.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #668 +/- ##
==========================================
+ Coverage 97.38% 97.53% +0.15%
==========================================
Files 3 3
Lines 382 406 +24
Branches 154 160 +6
==========================================
+ Hits 372 396 +24
Misses 10 10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Replace the standalone unit tests with end-to-end tests that go through the full webpack pipeline — same pattern used by `test/minify-option.test.js` for `terserMinify`, `swcMinify`, `esbuildMinify`, and `jsonMinify`. Each test now spins up a webpack compiler with `getCompiler`, applies a `TerserPlugin` configured for HTML, runs `compile`, and snapshots the emitted assets, errors and warnings via `readsAssets` / `getErrors` / `getWarnings`. New fixtures (`file.html`, `fragment.html`, plus matching `html.js`/`html-fragment.js` entries that reference them via `new URL(...)`) drive the asset emission, mirroring the existing `fixtures/json.js` / `fixtures/file.json` setup for `jsonMinify`. Coverage: each HTML minimizer (`htmlMinifierTerser`, `swcMinifyHtml`, `swcMinifyHtmlFragment`, `minifyHtmlNode`) is exercised with default options, plus dedicated cases for custom `minimizerOptions`, `parallel: true` / `false` (htmlMinifierTerser, which supports worker threads), and an array-of-`minify` chaining case.
Fold the 10 HTML-minimizer cases (and their snapshots) into the existing `minify option` describe block in `test/minify-option.test.js`, alongside the JS, JSON, and esbuild cases that already live there. The standalone `test/htmlMinimizers.test.js` and its dedicated snapshot file are removed. The HTML fixtures (`fixtures/file.html`, `fixtures/fragment.html`, `fixtures/html.js`, `fixtures/html-fragment.js`) stay where they are and are now consumed from `minify-option.test.js`.
- Quote `parallel` and `true`/`false` with double quotes (matching the existing 'should work when the "parallel" option is "true"' style at the top of the file). - Rename the array-of-`minify` chaining case to mirror the existing "should work when \`minify\` is an array of functions" wording. Snapshots are regenerated under the new keys; obsolete keys removed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Move the HTML minifier implementations from
html-minimizer-webpack-plugininto this plugin so HTML assets can be minified via the standard
TerserPlugininterface. Adds four new static helpers:TerserPlugin.htmlMinifierTerser(useshtml-minifier-terser)TerserPlugin.swcMinifyHtml(uses@swc/htmlfor full documents)TerserPlugin.swcMinifyHtmlFragment(uses@swc/htmlfor fragments)TerserPlugin.minifyHtmlNode(uses@minify-html/node)The HTML packages are declared as optional peer dependencies — install
only the one you actually use. Documentation in the README now includes
a dedicated HTML section with usage examples for each minimizer.