Skip to content

Commit 1c67141

Browse files
fix(css): keep minified CSS safe for older browsers and drop dead declarations (#22696)
* fix(css): read a box shorthand's printed sides where two of them touch The print writes `.2em .4em` as `.2em.4em` and `0 -2px` as `0-2px`, but lowering and folding split the value on spaces alone. Lowering `inset:.2em .4em` for Chrome 80 wrote `top:.2em.4em` on every side, which the engine drops, and `margin:.2em 0 .2em .4em;margin-right:2em` never folded. An `overflow` longhand now folds into the shorthand too, where every target reads both keywords. * fix(css): drop dead fallbacks and declarations a later same-selector rule overrides - read a multi-value text-decoration where every target does, and drop the -webkit-text-decoration twin beside it - drop outline's currentcolor beside a non-auto style where every target starts outline-color at CSS UI 4's auto - take out of an earlier rule with the same selector, in the same scope, each declaration a later rule writes again (not across a kept comment, a rollback keyword, keyframes or distant merges) - drop a hex fallback before an alpha hex every target reads - fold a longhand list into a multi-layer transition/animation, one per layer - background:transparent -> none; a centered top/bottom position -> keyword - sort a type selector before its [attr] variants * fix(css): name a centered edge only where every target reads the lone keyword Presto took -o-transform-origin keywords only as a pair, so a position written as percentages stays one unless the support data says otherwise. * fix(css): keep minified CSS safe for older browsers - with no browserslist, minify CSS for browserslist's defaults rather than for every current engine, unless dropOverriddenDeclarations asks for that - keep a shadow's currentcolor where Safari, iOS or WebKit Android is a target - keep a flex value's parts where IE is a target - write a :-webkit-any()/:-moz-any() copy only where each argument weighs one class, as the vendor form does - keep the space between touching tokens for engines older than custom properties (IE, Presto, WebKit Android) - part a fallback color from what follows it: #7f007f url(x), not one hash * revert(css): drop a shadow's currentcolor for every target again The WebKit gate rested on an MDN note no engine here could confirm. * fix(css): minify a second time to the same output - note every qualified rule for the same-selector drop, flat or not, and read the earlier one as flat only when it is rewritten - drop only after every copy in the piece is taken back - leave a named layer's rules alone, as the gathered blocks are - write background:transparent none as none too * fix(css): leave unicode-range unspaced and read every one-class :is() argument - an old engine's spacing skips a unicode-range value: U+131-140 is one range - a non-ASCII or escaped class, and a comma inside an attribute's string, no longer keep an :is() from its :-webkit-any()/:-moz-any() copy
1 parent 3c95c6f commit 1c67141

16 files changed

Lines changed: 1001 additions & 85 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Keep minified CSS safe for older browsers; drop dead fallbacks and overrides.

‎lib/config/defaults.js‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,12 +2627,21 @@ const applyOptimizationDefaults = (
26272627
// prefixes and every spelling a target can read, so `vendorPrefixes`
26282628
// turns off the first alone — resolving it is what the second needs.
26292629
const { target } = compiler.options;
2630-
const browsers = target
2630+
const context = /** @type {Context} */ (compiler.options.context);
2631+
const named = target
26312632
? getTargetsBrowsers(
26322633
Array.isArray(target) ? target : [target],
2633-
/** @type {Context} */ (compiler.options.context)
2634+
context
26342635
)
26352636
: undefined;
2637+
// A target naming no browsers is still served to some: browserslist's own
2638+
// `defaults` are them, where none would read as "every current engine" —
2639+
// unless `dropOverriddenDeclarations` asks for exactly that assumption.
2640+
const browsers =
2641+
named ||
2642+
(cssOptions !== undefined && cssOptions.dropOverriddenDeclarations
2643+
? undefined
2644+
: getTargetsBrowsers(["browserslist:defaults"], context));
26362645
const cssEnvironment = {
26372646
browsers,
26382647
vendorPrefixes:

0 commit comments

Comments
 (0)