Skip to content

Commit 0a413e7

Browse files
docs: list every css and html minimizer option
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.
1 parent de017aa commit 0a413e7

1 file changed

Lines changed: 73 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,13 +1452,79 @@ through their own `filter`, and both run in the worker pool.
14521452
`optimization.minimize.html` respectively. `environment` carries what the
14531453
target can read (`{ browsers, vendorPrefixes }`, the CSS entries of
14541454
[`output.environment`](https://webpack.js.org/configuration/output/#outputenvironment)),
1455-
so a spelling the target could not parse is never reached for; the rest is
1456-
`convertLengthUnits`, `rewriteCustomProperties`, `unusedSymbols`,
1457-
`pseudoClasses` and the per-transform switches.
1458-
1459-
`htmlMinify` runs the CSS minifier over every inline `<style>` and `style=""`,
1460-
so it takes both: `environment` stays **top level**, shared by the document and
1461-
the CSS inside it, while the CSS-only knobs go under `css`. Give the two
1455+
so a spelling the target could not parse is never reached for.
1456+
1457+
#### `cssMinify` options
1458+
1459+
Every option is named directly on the object — the per-transform switches sit
1460+
beside the rest, not nested.
1461+
1462+
| Option | Type | Default | What it does |
1463+
| :------------------------ | :-------------------------------------------------- | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ |
1464+
| `environment` | `{ browsers?: string[], vendorPrefixes?: boolean }` | — | What the target can read. `browsers` is a browserslist selection; `vendorPrefixes: false` leaves prefixes alone. |
1465+
| `as` | `"stylesheet" \| "block-contents"` | `"stylesheet"` | Which production to read the source as. The plugin sets it — a `style=""` arrives as `"block-contents"`. |
1466+
| `convertLengthUnits` | `boolean` | `false` | Rewrite a length into a shorter unit it is exactly equal in (`16px` → `1pc`). Off because it earns nothing once compressed. |
1467+
| `rewriteCustomProperties` | `boolean` | `false` | Shorten a custom property's value like any other (`--x:#ffffff` → `--x:#fff`). Off because `getPropertyValue()` hands that text back. |
1468+
| `unusedSymbols` | `string[]` | — | Names a whole-project analysis found unused; a bare name is a class, id or `@keyframes`, a `--`-prefixed one a custom property. |
1469+
| `pseudoClasses` | `{ [name: string]: string }` | — | Write a pseudo-class as a class instead, so a script can apply it where the engine does not. |
1470+
| `renderEmbeddedSource` | function | — | **Owned by the plugin** — do not pass it. |
1471+
1472+
Per-transform switches, each on unless set to `false`:
1473+
1474+
| Switch | What it rewrites |
1475+
| :--------------------- | :----------------------------------------------------------------------------------------------------------------------- |
1476+
| `colorFallbacks` | Writes a color the target cannot read as an extra declaration before it, in a spelling it does read. |
1477+
| `lowerUnsupported` | Writes a spelling the target cannot read as one it can — the same value, said another way. |
1478+
| `foldCase` | Lowercases a name that matches ASCII case-insensitively (at-rule, property, pseudo, function, unit, keyword). |
1479+
| `rewriteEscapes` | Writes an escaped identifier the shortest way that names it. |
1480+
| `comments` | Which comments survive: `"some"` (default), `true` / `"all"`, `false`, or a pattern / predicate over the comment's text. |
1481+
| `resolveCustomAtRules` | Inlines what `@custom-media` / `@custom-selector` names, and drops the rule that named it. |
1482+
| `mergeLonghands` | Writes a family of longhands as the one shorthand that sets them. |
1483+
| `mergeRules` | Joins rules printing the same block, at-rules sharing a prelude, and a `@layer` block a later sibling reopens. |
1484+
| `normalizeQuotes` | Normalizes quoting of strings, `url()`, font families and attribute values. |
1485+
| `reduceFunctions` | Computes a call into the shorter call naming the same value (`calc()`, transforms, gradients, easings, filters). |
1486+
| `removeDeadRules` | Drops a rule or declaration nothing can read — an empty rule, one an identical later one supersedes. |
1487+
| `rewriteDirSelector` | Writes a `:dir()` the target cannot read as the `[dir]` attribute selector. |
1488+
| `shortenColors` | Writes each color in the shortest spelling of the same value. |
1489+
| `shortenMediaQueries` | Writes a media feature in its range spelling and collapses an `and` of two into the interval. |
1490+
| `shortenNumbers` | Writes each number in its shortest equal spelling. |
1491+
| `shortenSelectors` | Rewrites a selector into a shorter equal one. |
1492+
| `shortenValues` | Writes a value the shortest way its property's own grammar allows. |
1493+
1494+
#### `htmlMinify` options
1495+
1496+
| Option | Type | Default | What it does |
1497+
| :-------------------------- | :---------------------------------------------- | :-------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1498+
| `environment` | same as `cssMinify` | — | CSS's, not HTML's: handed to the CSS minifier this runs over inline CSS. |
1499+
| `css` | object | `{}` | The CSS minifier's options for that inline CSS — see below. |
1500+
| `collapseWhitespace` | `boolean \| "conservative" \| "smart" \| "all"` | `false` | Collapses each run of whitespace in text, except where an ancestor renders it verbatim; `"smart"` also drops what sits against a block edge, `"all"` every edge. |
1501+
| `removeEmptyAttributes` | `boolean` | `false` | Drops an attribute whose empty value leaves it in the state its absence gives. |
1502+
| `removeEmptyElements` | `boolean` | `false` | Drops an element with no children and no attributes, unless its bare form is meaningful. |
1503+
| `mergeStyles` | `boolean` | `false` | Prints a run of adjacent `<style>` elements as one sheet. |
1504+
| `sortAttributes` | `boolean` | `false` | Prints attributes commonest name first, ties by name — nothing in HTML reads the order. |
1505+
| `sortTokenLists` | `boolean` | `false` | Prints every token list the DOM reads as a set (`class`, `rel`, `part`, …) in token order. |
1506+
| `removeRedundantAttributes` | `boolean \| "smart" \| "all"` | `false` | Drops an attribute whose value is the element's own default; `"all"` also drops spec defaults a selector can match. |
1507+
| `removeImpliedTags` | `boolean \| "smart" \| "all"` | `"smart"` | How much of the `<html>` / `<head>` / `<body>` shell may be left out: `"smart"` only the `<html>` start tag, `true` / `"all"` all six. |
1508+
| `minifyConditionalComments` | `boolean` | `false` | Minifies the markup inside a conditional comment's body. |
1509+
| `renderEmbeddedSource` | function | — | **Owned by the plugin** — do not pass it. |
1510+
1511+
Per-transform switches, each on unless set to `false`:
1512+
1513+
| Switch | What it rewrites |
1514+
| :------------------------------ | :---------------------------------------------------------------------------------------------------------------- |
1515+
| `collapseBooleanAttributes` | Writes a boolean attribute spelled with its own name (`disabled="disabled"`) as the bare name. |
1516+
| `comments` | Which comments survive — same values as CSS's. One a parser or server reads is kept regardless. |
1517+
| `normalizeAttributeQuotes` | Drops or re-picks an attribute value's quotes. |
1518+
| `normalizeEnumeratedAttributes` | Folds an enumerated value to the keyword it names. |
1519+
| `normalizeListAttributes` | Normalizes a space-, comma- or descriptor-separated list (`class`, `rel`, `srcset`, `sizes`, viewport `content`). |
1520+
| `normalizeNumericAttributes` | Writes an integer attribute the one way its rules read it. |
1521+
| `removeOptionalTags` | Leaves out an optional tag other than the shell, which is `removeImpliedTags`. |
1522+
1523+
The `css` object takes the CSS minifier's `convertLengthUnits`,
1524+
`rewriteCustomProperties`, `unusedSymbols` and `pseudoClasses`, plus the CSS
1525+
per-transform switches. `environment` is **not** among them: `htmlMinify` runs
1526+
the CSS minifier over every inline `<style>` and `style=""`, so `environment`
1527+
stays **top level**, shared by the document and the CSS inside it. Give the two
14621528
minimizers the same `environment` and a `.css` asset and the same declaration
14631529
inline agree about the target:
14641530

0 commit comments

Comments
 (0)