You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5a8fa6c
Browse filesBrowse the repository at this point in the historyBrowse files
feat: configure or exclude each asset type's minifier via optimization.minimize (#21663)
* feat: configure or exclude each asset type's minifier via optimization.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.
* feat: normalize optimization.minimize and hand JS minimizer options through 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).
* style: tighten comments to the two-line limit and use precise minimizer option types
* feat(html): add optimization.minimize.html.collapseWhitespace
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.
* style: trim collapse-whitespace comments and stabilize formatting
Prettier's first pass over two untouched regions was not a fixed point;
the committed form now matches what `--check` verifies.
* test(html): drive collapseWhitespace through SourceProcessor in-process
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.
* What the CSS minimizer may do beyond the transforms that always apply. Applies wherever it runs: on `.css` assets and on the inline `<style>` / `style=""` the HTML minimizer hands it.
2360
+
* @since 5.110.0
2361
+
*/
2362
+
exportinterfaceOptimizationMinimizeCss{
2363
+
/**
2364
+
* Rewrite a length into a shorter unit it is exactly equal in (`16px` -> `1pc`). Off by default: the authored unit is lost, and once the asset is compressed the rewrite rarely earns anything.
2365
+
* @since 5.110.0
2366
+
*/
2367
+
convertLengthUnits?: boolean;
2368
+
}
2369
+
/**
2370
+
* What the HTML minimizer may do beyond the transforms that always apply.
2371
+
* @since 5.110.0
2372
+
*/
2373
+
exportinterfaceOptimizationMinimizeHtml{
2374
+
/**
2375
+
* Collapse each run of whitespace in text to a single space. Left alone inside `pre`, `textarea` and `listing`, where whitespace renders verbatim, and never removed entirely — dropping it would join two inline elements that render apart.
2376
+
* @since 5.110.0
2377
+
*/
2378
+
collapseWhitespace?: boolean;
2379
+
}
2380
+
/**
2381
+
* Options handed as-is to the JavaScript minimizer (terser-compatible). Defaults to `{ compress: { passes: 2 }}`.
Copy file name to clipboardExpand all lines: lib/css/cssMinify.js
+6-13Lines changed: 6 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@
22
22
* re-resolves in the worker — via the installed package, or the dev self-link.
23
23
* @param {{ [file: string]: string }} input a single `{ filename: code }` entry
24
24
* @param {object=} sourceMap the asset's input source map — the plugin chains it onto the map returned here, so it isn't read directly
25
-
* @param {object=} minimizerOptions minimizer options — `environment` carries the target's CSS abilities (see `output.environment`), so a spelling the target cannot read is not reached for
25
+
* @param {{ environment?: CssEnvironment, convertLengthUnits?: boolean }=} minimizerOptions minimizer options — `environment` carries the target's CSS abilities (see `output.environment`), so a spelling the target cannot read is not reached for; the rest is `optimization.minimize.css` (e.g. `convertLengthUnits`)
26
26
* @returns {{ code: string, map: SourceMap }} the minified CSS and its input->output source map
Copy file name to clipboardExpand all lines: lib/html/htmlMinify.js
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@
23
23
* re-resolves in the worker — via the installed package, or the dev self-link.
24
24
* @param {{ [file: string]: string }} input a single `{ filename: code }` entry
25
25
* @param {(RawSourceMap | undefined)=} sourceMap input source map (unused: safe serialize keeps positions token-coarse, so no map is produced yet)
26
-
* @param {object=} minimizerOptions minimizer options — `environment` carries the target's CSS abilities, for the inline CSS this minifies
26
+
* @param {{ environment?: CssEnvironment, convertLengthUnits?: boolean, collapseWhitespace?: boolean }=} minimizerOptions minimizer options — `environment` and `convertLengthUnits` reach the CSS minifier this runs over inline CSS; the rest is `optimization.minimize.html`
0 commit comments