Skip to content

Commit c3a7f01

Browse files
build(css): widen the CSS minifier comparison to 14 tools and 27 stylesheets (#21963)
* build(css): compare against four more CSS minifiers esbuild and lightningcss gain target-aware arms, so `webpack+target` is read against what a rival makes of the same browserslist rather than against its untargeted default. cssnano's advanced preset and the Go `tdewolff/minify` add two lineages the set did not cover. * build(css): compare on seven more frameworks, and two more minifiers The added stylesheets are chosen for what they exercise rather than for popularity: PatternFly carries 2961 custom properties, Tabler 322 `color-mix()` calls, Fomantic-UI 1986 KB of legacy prefixed CSS, and 98.css/Spectre/Shoelace/ Beer CSS cover shapes the set had none of. `@swc/css` and `crass` join the tools, both of which refuse most real stylesheets — which is the row's point. * build(css): measure what rewriting custom properties is worth Every rival shortens a custom property's value unprompted, so a theme file that is mostly custom properties compared webpack's untouched output against their rewritten one. On Shoelace's light theme the arm closes a 656 byte gzip gap and ends 16 bytes ahead of lightningcss. * build: name the comparison packages cspell does not know The frameworks and the Go minifier the CSS comparison installs.
1 parent 473b19e commit c3a7f01

2 files changed

Lines changed: 104 additions & 0 deletions

File tree

‎cspell.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"backport",
2828
"backported",
2929
"basictest",
30+
"beercss",
3031
"beforeload",
3132
"behaviour",
3233
"bigint",
@@ -147,6 +148,7 @@
147148
"Flexbox",
148149
"fnmatch",
149150
"focusring",
151+
"fomantic",
150152
"fontobject",
151153
"formaction",
152154
"formaters",
@@ -307,6 +309,7 @@
307309
"parseargs",
308310
"passthrough",
309311
"pathinfo",
312+
"patternfly",
310313
"PCSL",
311314
"peakoss",
312315
"pebibytes",
@@ -444,8 +447,10 @@
444447
"systemjs",
445448
"tabatkins",
446449
"tabindex",
450+
"tabler",
447451
"tapable",
448452
"Tarjan",
453+
"tdewolff",
449454
"tebibytes",
450455
"templated",
451456
"templating",

‎tooling/compare-css-minifiers.js‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,40 @@ const CACHE = path.join(ROOT, "node_modules/.cache/css-minifier-comparison");
4040
const MODULES = path.join(CACHE, "node_modules");
4141

4242
const PACKAGES = [
43+
4344
"animate.css@4",
45+
"beercss@5",
4446
"bootstrap@5",
4547
"bulma@1",
4648
"clean-css@5",
49+
4750
"csso@5",
4851
"cssnano@7",
52+
"cssnano-preset-advanced@9",
4953
"daisyui@5",
5054
5155
"@fortawesome/fontawesome-free@6",
56+
"fomantic-ui-css@2",
5257
"foundation-sites@6",
5358
"lightningcss@1",
5459
"materialize-css@1",
5560
"milligram@1",
5661
"normalize.css@8",
62+
"@patternfly/patternfly@6",
5763
"@picocss/pico@2",
5864
"postcss@8",
5965
"postcss-selector-parser@7",
6066
"@primer/css@21",
6167
"purecss@3",
6268
"sanitize.css@13",
69+
"@shoelace-style/shoelace@2",
70+
71+
6372
"semantic-ui-css@2",
73+
"@tabler/core@1",
6474
"tachyons@4",
6575
"tailwindcss@4",
76+
"@tdewolff/minify@2",
6677
"@tailwindcss/cli@4",
6778
"uikit@3",
6879
"water.css@2"
@@ -196,20 +207,27 @@ const load = (name) => require(path.join(MODULES, name));
196207
// animation and reset sheets) whose CSS looks nothing like a framework's.
197208
/** @type {[string, string][]} */
198209
const INSTALLED_FIXTURES = [
210+
["98.css", "98.css/dist/98.css"],
199211
["Animate.css 4", "animate.css/animate.css"],
212+
["Beer CSS 5", "beercss/dist/cdn/beer.css"],
200213
["Bootstrap 5 (full)", "bootstrap/dist/css/bootstrap.css"],
201214
["Bootstrap 5 (grid)", "bootstrap/dist/css/bootstrap-grid.css"],
202215
["Bulma 1", "bulma/css/bulma.css"],
216+
["Fomantic-UI 2", "fomantic-ui-css/semantic.css"],
203217
["Font Awesome 6", "@fortawesome/fontawesome-free/css/all.css"],
204218
["Foundation 6", "foundation-sites/dist/css/foundation.css"],
205219
["Materialize 1", "materialize-css/dist/css/materialize.css"],
206220
["Milligram 1", "milligram/dist/milligram.css"],
207221
["normalize.css 8", "normalize.css/normalize.css"],
222+
["PatternFly 6", "@patternfly/patternfly/patternfly-base.css"],
208223
["Pico 2", "@picocss/pico/css/pico.css"],
209224
["Primer 21", "@primer/css/dist/primer.css"],
210225
["Pure 3", "purecss/build/pure.css"],
211226
["sanitize.css 13", "sanitize.css/sanitize.css"],
212227
["Semantic UI 2", "semantic-ui-css/semantic.css"],
228+
["Shoelace 2 (light)", "@shoelace-style/shoelace/dist/themes/light.css"],
229+
["Spectre 0.5", "spectre.css/dist/spectre.css"],
230+
["Tabler 1", "@tabler/core/dist/css/tabler.css"],
213231
["Tachyons 4", "tachyons/css/tachyons.css"],
214232
["UIkit 3", "uikit/dist/css/uikit.css"],
215233
["Water.css 2", "water.css/out/water.css"]
@@ -247,6 +265,18 @@ const MINIFIERS = [
247265
})
248266
).code
249267
],
268+
[
269+
// The rivals shorten a custom property's value the way they shorten any
270+
// other; webpack holds off unless told, since `getPropertyValue()` reads it.
271+
"webpack+target+vars",
272+
() => async (css) =>
273+
(
274+
await cssMinify({ "input.css": css }, undefined, {
275+
environment: { browsers: MODERN_BROWSERS },
276+
rewriteCustomProperties: true
277+
})
278+
).code
279+
],
250280
[
251281
"esbuild",
252282
() => {
@@ -255,6 +285,20 @@ const MINIFIERS = [
255285
(await esbuild.transform(css, { loader: "css", minify: true })).code;
256286
}
257287
],
288+
[
289+
"esbuild+target",
290+
() => {
291+
const esbuild = load("esbuild");
292+
// esbuild names its targets rather than reading browserslist, so the
293+
// query resolves to the `<name><major>` strings it accepts.
294+
const target = MODERN_BROWSERS.map((entry) =>
295+
entry.replace(" ", "").replace(/\..*$/, "")
296+
);
297+
return async (css) =>
298+
(await esbuild.transform(css, { loader: "css", minify: true, target }))
299+
.code;
300+
}
301+
],
258302
[
259303
"csso",
260304
() => {
@@ -294,6 +338,22 @@ const MINIFIERS = [
294338
.code.toString("utf8");
295339
}
296340
],
341+
[
342+
"lightningcss+target",
343+
() => {
344+
const lightningcss = load("lightningcss");
345+
const targets = lightningcss.browserslistToTargets(MODERN_BROWSERS);
346+
return (css) =>
347+
lightningcss
348+
.transform({
349+
filename: "input.css",
350+
code: Buffer.from(css),
351+
minify: true,
352+
targets
353+
})
354+
.code.toString("utf8");
355+
}
356+
],
297357
[
298358
"cssnano",
299359
() => {
@@ -302,6 +362,45 @@ const MINIFIERS = [
302362
return async (css) =>
303363
(await postcss([cssnano]).process(css, { from: undefined })).css;
304364
}
365+
],
366+
[
367+
// The preset cssnano does not ship on by default: it also merges rules,
368+
// rebases `z-index` and reduces idents, so it diverges where the rest agree.
369+
"cssnano advanced",
370+
() => {
371+
const postcss = load("postcss");
372+
const cssnano = load("cssnano");
373+
const advanced = load("cssnano-preset-advanced");
374+
return async (css) =>
375+
(
376+
await postcss([cssnano({ preset: advanced() })]).process(css, {
377+
from: undefined
378+
})
379+
).css;
380+
}
381+
],
382+
[
383+
"tdewolff/minify",
384+
() => {
385+
const { minify } = load("@tdewolff/minify");
386+
return (css) => minify("text/css", css);
387+
}
388+
],
389+
[
390+
// Its documented entry point, which is what a user calls — it panics on a
391+
// stylesheet with anything much in it, and the row then reads as a refusal.
392+
"@swc/css",
393+
() => {
394+
const swc = load("@swc/css");
395+
return (css) => swc.minifySync(Buffer.from(css), {}).code.toString();
396+
}
397+
],
398+
[
399+
"crass",
400+
() => {
401+
const crass = load("crass");
402+
return (css) => crass.parse(css).optimize({ o1: true }).toString();
403+
}
305404
]
306405
];
307406

0 commit comments

Comments
 (0)