perf(build): the stylesheet minifier had never run

It looked for the tag written as `css` immediately followed by a
backtick. The plugin is a Rollup transform, so the module has already
been through TypeScript by the time it arrives, and the TS printer puts
a space there: `css `. The guard therefore returned null for every
stylesheet in the project, and minification never ran once — around
23 KB of explanatory comments went to every user in every release.

Matching the tag as a word with optional whitespace turns it on:

  chunk, raw       1 079 508 -> 1 021 115 B   (-58 393)
  initial view     300 111 -> 287 284 B gzip  (-12 816)
  room to the budget   955 -> 13 782 B

The ceiling moves down with the fact, as the tool asks when a graph
shrinks past the band.

The risk is not the two lines; it is that 23 KB of CSS is minified for
the first time. Two witnesses cover it: a browser smoke that puts the
original and the minified text into separate stylesheets and compares
the serialised rules — 1 049 of them, identical up to the whitespace
policy the minifier declares — and a test that takes real comment text
out of src/styles and requires it to be absent from dist, so a plugin
that silently stops working cannot pass again.

Issue: #526
User-Visible: yes
This commit is contained in:
Codex
2026-09-11 10:12:13 +03:00
parent 7e39c3715c
commit 0a0a9f0f4c
54 changed files with 697 additions and 11698 deletions
+9 -5
View File
@@ -60,14 +60,18 @@ export function minifyCssText(source, label = '<css>') {
return out.trim();
}
const CSS_TAG = /(^|[^\w$.])css\s*`/;
export function minifyStaticCssTemplates(code, id = '<module>') {
let cursor = 0;
let output = '';
let changed = false;
while (true) {
const start = code.indexOf('css`', cursor);
if (start < 0) break;
let end = start + 4;
const match = CSS_TAG.exec(code.slice(cursor));
if (!match) break;
const start = cursor + match.index + match[1].length;
const tagLength = match[0].length - match[1].length;
let end = start + tagLength;
let escaped = false;
for (; end < code.length; end += 1) {
const char = code[end];
@@ -85,7 +89,7 @@ export function minifyStaticCssTemplates(code, id = '<module>') {
if (char === '`') break;
}
if (end >= code.length) throw new Error(`${id}:${start}: unclosed css template`);
const css = code.slice(start + 4, end);
const css = code.slice(start + tagLength, end);
output += code.slice(cursor, start);
output += `css\`${minifyCssText(css, `${id}:${start}`)}\``;
cursor = end + 1;
@@ -99,7 +103,7 @@ export function cssTemplateMinifier() {
return {
name: 'houseplan-css-template-minifier',
transform(code, id) {
if (!id.endsWith('.ts') || !code.includes('css`')) return null;
if (!id.endsWith('.ts') || !CSS_TAG.test(code)) return null;
const transformed = minifyStaticCssTemplates(code, id);
return transformed == null ? null : { code: transformed, map: null };
},