Skip to content

Commit ead32d3

Browse files
feat(css): print a minified rule's declarations in one order by property family (#22513)
* feat(css): print a minified rule's declarations in one order by property family Brings back `reorderDeclarations`, on by default: a rule's declarations print family by family in the order lightningcss prints its handlers in, the properties no family names first where they were written, so blocks setting the same things read alike and compress smaller. Only what no order can decide moves. * feat(css): keep a family's declarations in the order written, and check the order in each engine Every member of a declaration family now shares one rank, so only whole families move, as in lightningcss: a spec relating two members before mdn-data does moves nothing. The equivalence suite asks each engine which longhands every ranked property sets and fails when the minifier moves one declaration past another setting the same longhand. * chore: fold the declaration order changeset into the pending CSS minify entry * fix(css): keep size in the sizing family, which WebKit reads as width and height The equivalence suite's declaration order check found that WebKit sets width and height from a size declaration outside @page, so moving size ahead of width changes what WebKit reads.
1 parent a3232d2 commit ead32d3

35 files changed

Lines changed: 1782 additions & 1140 deletions

File tree

‎.changeset/104-css-minify-shorthand-folds.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": minor
33
---
44

5-
Shorten CSS values, selectors and astral escapes, fold longhands, drop overridden rules and a source stylesheet's stale `sourceMappingURL` comment, and write `@charset "UTF-8"` exactly when the output holds a non-ASCII character.
5+
Shorten more CSS values and selectors, fold longhands and order declarations.

‎declarations/WebpackOptions.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,6 +3203,11 @@ export interface OptimizationMinimizeCss {
32033203
* @since 5.110.0
32043204
*/
32053205
removeDeadRules?: boolean;
3206+
/**
3207+
* Print a style rule's declarations in one order by property family, the properties no family names first where they were written, so blocks setting the same things read alike and compress smaller. Only declarations whose order nothing can see move: two spellings of one property, a shorthand and what it sets, two shorthands sharing a longhand, and a flow-relative side and a physical one keep theirs, and a block holding a property no dataset names or a nested rule is printed as written. On by default.
3208+
* @since 5.112.0
3209+
*/
3210+
reorderDeclarations?: boolean;
32063211
/**
32073212
* Shorten the values of custom properties (`--x: #ffffff` -> `#fff`, `--y: 0.5rem` -> `.5rem`), which are otherwise written back exactly as authored. Off by default: `getComputedStyle().getPropertyValue()` hands this text back, so a rewritten value is a different CSSOM — the one place a declaration's authored text survives. What it may rewrite is exactly what any other value's tokens may be, a color in a substitution's fallback included — that fallback being the property's value rather than the function's own argument.
32083213
* @since 5.110.0

0 commit comments

Comments
 (0)