From 5d52547978bb57fc3932a1b1cf1f9155e91f5fc4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 18 Jul 2026 17:34:51 +0000 Subject: [PATCH 1/2] feat(create-bestax): add bestax-optimize skill for shrinking built CSS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New Agent Skill teaching agents to reduce a bestax app's built CSS, cheapest lever first: measure raw+gzip (and stop if transfer size is already fine), switch prebuilt flavor (with the no-helpers hard gate), hand-rolled modular @use build (authoritative extras partial inventory), and import/icon-asset hygiene. First-party levers only — no third-party build plugins. Ships through all skill surfaces: sync-skills SKILLS array, the scaffolded CLAUDE.md skills list, skills/README.md, and the docs site (skills/optimize.mdx + intro + sidebar). No Storybook skill-example: the skill produces build config, nothing renderable. Closes #323 Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_018zYSCUhkobiaCv2MPvqvSt --- create-bestax/scripts/sync-skills.mjs | 1 + create-bestax/src/constants.ts | 1 + .../guides/getting-started/optimizing-css.md | 3 + docs/docs/skills/intro.md | 3 + docs/docs/skills/optimize.mdx | 71 +++++++ docs/sidebars.js | 1 + skills/README.md | 6 + skills/bestax-optimize/SKILL.md | 131 +++++++++++++ .../references/modular-build.md | 173 ++++++++++++++++++ 9 files changed, 390 insertions(+) create mode 100644 docs/docs/skills/optimize.mdx create mode 100644 skills/bestax-optimize/SKILL.md create mode 100644 skills/bestax-optimize/references/modular-build.md diff --git a/create-bestax/scripts/sync-skills.mjs b/create-bestax/scripts/sync-skills.mjs index cbf08dc4e..ffcf6e5f5 100644 --- a/create-bestax/scripts/sync-skills.mjs +++ b/create-bestax/scripts/sync-skills.mjs @@ -19,6 +19,7 @@ const SKILLS = [ 'bestax-theming', 'bestax-layout-scaffold', 'bestax-icons', + 'bestax-optimize', ]; if (!fs.existsSync(skillsSrc)) { diff --git a/create-bestax/src/constants.ts b/create-bestax/src/constants.ts index c794f1f9e..46ae945d1 100644 --- a/create-bestax/src/constants.ts +++ b/create-bestax/src/constants.ts @@ -127,6 +127,7 @@ automatically when the task matches: - **bestax-theming** — colors, branding, and dark mode via the \`Theme\` component (\`colorMode\`). - **bestax-layout-scaffold** — scaffold full pages (app shell, landing, centered, card grid). - **bestax-icons** — icons via \`Icon\`/\`IconText\`: library setup, name formats, variants, a11y. +- **bestax-optimize** — shrink the built CSS: measure raw+gzip, then flavor switch or a modular Sass build. Prefer the library's components and these skills over hand-written Bulma markup or custom CSS. diff --git a/docs/docs/guides/getting-started/optimizing-css.md b/docs/docs/guides/getting-started/optimizing-css.md index 41bd38691..3f2829f5f 100644 --- a/docs/docs/guides/getting-started/optimizing-css.md +++ b/docs/docs/guides/getting-started/optimizing-css.md @@ -108,6 +108,9 @@ of maintaining the import list as your usage grows. ## Related +- [Optimize skill](../../skills/optimize.mdx) — an Agent Skill that applies this guide's + levers to your app (measure, flavor switch, modular build) via Claude Code or any + skills.sh-compatible agent. - [CSS Variations](./variations.md) — what each flavor includes. - [Modular](./modular.md) — JS tree-shaking and the three CSS loading strategies. - [Dark Mode & Contrast](../features/css-variables.md#dark-mode--contrast) — pin the scheme diff --git a/docs/docs/skills/intro.md b/docs/docs/skills/intro.md index 22de5df4e..28b58735c 100644 --- a/docs/docs/skills/intro.md +++ b/docs/docs/skills/intro.md @@ -17,6 +17,7 @@ npx skills add https://github.com/allxsmith/bestax --skill bestax-form npx skills add https://github.com/allxsmith/bestax --skill bestax-theming npx skills add https://github.com/allxsmith/bestax --skill bestax-layout-scaffold npx skills add https://github.com/allxsmith/bestax --skill bestax-icons +npx skills add https://github.com/allxsmith/bestax --skill bestax-optimize ``` Starting a new app? `pnpm create bestax@latest` offers to **preinstall these skills** into the @@ -35,3 +36,5 @@ Then explore each skill — what it does, how to install it, and live examples: to a complete responsive page using the layout archetypes. - **[Icons](./icons)** — use `Icon`/`IconText` with any of the five supported icon libraries: per-library setup, name formats, variants, and decorative-vs-labeled accessibility. +- **[Optimize](./optimize)** — reduce the built CSS size: measure raw+gzip, then the cheapest + first-party lever that fits (lighter flavor, modular Sass build, import/asset hygiene). diff --git a/docs/docs/skills/optimize.mdx b/docs/docs/skills/optimize.mdx new file mode 100644 index 000000000..78cdf1d2a --- /dev/null +++ b/docs/docs/skills/optimize.mdx @@ -0,0 +1,71 @@ +--- +title: Optimize +sidebar_label: Optimize +sidebar_position: 6 +--- + +# Optimize skill + +The [`bestax-optimize`](https://github.com/allxsmith/bestax/blob/main/skills/bestax-optimize/SKILL.md) +skill teaches an agent to reduce the built CSS size of an app using +`@allxsmith/bestax-bulma`: measure raw and gzip size first, then apply the cheapest lever +that fits — a lighter prebuilt CSS flavor, a hand-rolled modular Sass build, or import and +icon-asset hygiene. First-party levers only: it uses the library's own shipped CSS builds and +SCSS sources, never third-party build plugins. + +## Install + +```bash +npx skills add https://github.com/allxsmith/bestax --skill bestax-optimize +``` + +## What it teaches + +- **Measure first, and know when to stop** — build, then measure the CSS raw (`wc -c`) and + gzipped (`gzip -c … | wc -c`), and judge by the **gzip** number: the ~800 KB of CSS in + `dist/` is ~82 KB over the wire. If that's within budget, the honest answer is "your + CSS is already fine" — and the skill says so instead of inventing work. +- **Lever 1: a lighter prebuilt flavor** — a one-line import change between the shipped + builds, with the measured size table and the hard gate: `no-helpers` may only be + recommended after checking the app uses **no helper props** (`mt="4"`, + `textColor="primary"`, `display="flex"`, …), because that flavor drops the classes those + props compile to. + + ```tsx + // before + import '@allxsmith/bestax-bulma/bestax.css'; // ~82 KB gzip + // after — the app pins a single color scheme + import '@allxsmith/bestax-bulma/versions/bestax-no-dark-mode.css'; // ~70 KB gzip + ``` + +- **Lever 2: a modular Sass build** — compile only the Bulma modules and bestax extras + partials the app actually imports, derived component-by-component: + + ```scss + // src/styles.scss + @use 'bulma/sass/base'; + @use 'bulma/sass/themes'; + @use 'bulma/sass/elements/button'; + @use 'bulma/sass/components/card'; + @use '@allxsmith/bestax-bulma/scss/components/dialog'; + @use 'bulma/sass/helpers/flexbox'; + ``` + +- **Lever 3: import & icon-asset hygiene** — convert `import * as` to named imports so JS + tree shaking works, and delete icon-library packages/CDN scripts the app never renders — + icon fonts often outweigh Bulma itself. + +## Reference material the agent reads on demand + +- [`references/modular-build.md`](https://github.com/allxsmith/bestax/blob/main/skills/bestax-optimize/references/modular-build.md) + — the full Lever 2 procedure: the component→partial mapping rule, the authoritative + bestax extras partial inventory (more complete than the docs example), Bulma helper + categories, and a worked `styles.scss` for the starter app. + +## Related + +- [Optimizing CSS Size](../guides/getting-started/optimizing-css.md) — the guide this skill + acts on, with the measured flavor table. +- [Modular](../guides/getting-started/modular.md) — JS tree-shaking and the three CSS loading + strategies (Option C is the modular Sass pattern). +- [CSS Variations](../guides/getting-started/variations.md) — what each flavor includes. diff --git a/docs/sidebars.js b/docs/sidebars.js index 769efa246..cf8853719 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -37,6 +37,7 @@ const sidebars = { 'skills/theming', 'skills/layout-scaffold', 'skills/icons', + 'skills/optimize', ], }, ], diff --git a/skills/README.md b/skills/README.md index 24b616e04..96acb6fd8 100644 --- a/skills/README.md +++ b/skills/README.md @@ -16,6 +16,7 @@ directory the agent reads on demand. | [`bestax-theming`](./bestax-theming/SKILL.md) | **Theming** — customize colors, branding, fonts/radius tokens, and dark mode by overriding Bulma's `--bulma-*` variables with the `Theme` component. | | [`bestax-layout-scaffold`](./bestax-layout-scaffold/SKILL.md) | **Layout scaffolding** — turn a high-level request (dashboard, landing page, auth page, catalog) into a complete responsive page from named layout archetypes. | | [`bestax-icons`](./bestax-icons/SKILL.md) | **Icons** — the `Icon`/`IconText` components and the five supported libraries (Font Awesome, MDI, Ionicons, Material Icons/Symbols): setup, name formats, variants, and accessibility. | +| [`bestax-optimize`](./bestax-optimize/SKILL.md) | **CSS size** — measure raw+gzip and shrink the built stylesheet: a lighter prebuilt flavor, a hand-rolled modular Sass build, and import/icon-asset hygiene. First-party levers only. | ## Install @@ -27,6 +28,7 @@ npx skills add https://github.com/allxsmith/bestax --skill bestax-form npx skills add https://github.com/allxsmith/bestax --skill bestax-theming npx skills add https://github.com/allxsmith/bestax --skill bestax-layout-scaffold npx skills add https://github.com/allxsmith/bestax --skill bestax-icons +npx skills add https://github.com/allxsmith/bestax --skill bestax-optimize ``` ## Layout @@ -72,6 +74,10 @@ skills/ icon-libraries.md # per-library setup, name formats, variants, troubleshooting examples/ icon-usage.tsx # ConfigProvider + sizes/variants/colors + a11y patterns + bestax-optimize/ + SKILL.md + references/ + modular-build.md # component→partial mapping, extras inventory, worked styles.scss ``` > `component-catalog.md` is generated from the API docs by `scripts/gen-component-catalog.mjs` diff --git a/skills/bestax-optimize/SKILL.md b/skills/bestax-optimize/SKILL.md new file mode 100644 index 000000000..5127adcd8 --- /dev/null +++ b/skills/bestax-optimize/SKILL.md @@ -0,0 +1,131 @@ +--- +name: bestax-optimize +description: Reduce the built CSS size of an app using @allxsmith/bestax-bulma — measure raw and gzip size, then apply the cheapest lever that fits (lighter prebuilt CSS flavor, hand-rolled modular Sass build, import and icon-asset hygiene). Use when the CSS bundle looks too big, a size budget or Lighthouse audit flags stylesheet weight, switching bestax.css to a versions/*.css flavor, or setting up a modular @use Bulma/Sass build. +license: MIT +--- + +# Optimizing CSS size with @allxsmith/bestax-bulma + +The JS side is tree-shakable (the **entire** library is ~49 KB min+gzip). The stylesheet is +not: a prebuilt flavor ships all of Bulma + the bestax extras regardless of which components +the app renders. Judge stylesheet weight by the **gzipped** transfer size — never the raw +`dist/` number. + +## Always measure first + +Run the production build, then measure the built CSS — raw and gzip: + +```sh +npm run build +wc -c dist/assets/*.css # raw bytes (what Vite reports) +gzip -c dist/assets/*.css | wc -c # transfer bytes (what users download) +``` + +Re-measure after **every** step below and report the before/after delta (raw + gzip). Never +claim a saving without a number. + +⚠️ **~800 KB raw is ~82 KB over the wire.** Seeing ~800 KB of CSS in `dist/` is expected +with the default flavor, not a build misconfiguration — servers and CDNs gzip/brotli by +default. If the gzip number is already within the app's budget, say so and stop: "your CSS is +already fine" is a valid, honest outcome. + +## Decision flow + +Cheapest first. Use only the library's own shipped CSS builds and SCSS sources — do not add +third-party build plugins (no CSS purgers/post-processors). + +1. **Flavor switch** — one-line import change, minutes (up to ~15 KB gzip). +2. **Modular Sass build** — small `@use` file, the biggest honest win. +3. **Import & icon-asset hygiene** — minor; JS and icon fonts, not the Bulma CSS. + +## Lever 1 — lighter prebuilt flavor + +Swap the single CSS import (in `src/main.tsx` / `src/main.jsx`) between the shipped flavors. +Measured sizes drift slightly between releases — hence measure: + +| Flavor | Import | Raw | Gzip | +| ------------ | -------------------------------------------------------------------- | -----: | -----: | +| complete | `import '@allxsmith/bestax-bulma/bestax.css';` | ~800KB | ~82 KB | +| no-dark-mode | `import '@allxsmith/bestax-bulma/versions/bestax-no-dark-mode.css';` | ~680KB | ~70 KB | +| no-helpers | `import '@allxsmith/bestax-bulma/versions/bestax-no-helpers.css';` | ~595KB | ~67 KB | + +Prefixed variants (`versions/bestax-prefixed.css` ~875 KB/~84 KB, +`versions/bestax-no-helpers-prefixed.css` ~655 KB/~69 KB) exist for CSS-collision +**compatibility, not size** — a prefixed flavor must pair with +`` at the app root, and switching a non-prefixed app to +one is never a size optimization. + +- `no-dark-mode` (~12 KB gzip saved) — only when the app pins a single color scheme (a fixed + `Theme colorMode` / `data-theme`). +- `no-helpers` (~15 KB gzip saved) — **hard gate below**. + +⚠️ **The `no-helpers` gate: check for helper props first.** That flavor drops every class the +helper props compile to — components still render, but the props silently do nothing. Before +recommending it, grep the app's source for helper props on bestax components: + +- spacing: `m`, `mt`, `mr`, `mb`, `ml`, `mx`, `my`, `p`, `pt`, `pr`, `pb`, `pl`, `px`, `py` +- color: `color`, `backgroundColor` (+ `colorShade`/`backgroundColorShade`), `textColor`, `bgColor` +- typography: `textSize`, `textAlign`, `textTransform`, `textWeight`, `fontFamily` +- display/visibility: `display`, `visibility` (+ `displayMobile`…`visibilityFullhd` viewport variants) +- flexbox: `flexDirection`, `flexWrap`, `justifyContent`, `alignContent`, `alignItems`, `alignSelf`, `flexGrow`, `flexShrink` +- misc: `float`, `overflow`, `overlay`, `interaction`, `cursor`, `radius`, `shadow`, `skeleton`, `clearfix`, `relative`, `fullHeight` + +…and for raw Bulma helper classes in `className` strings (`is-*`, `has-*`, `m*-*`, `p*-*`, +`is-size-*`, `is-hidden*`, `is-flex*`). **Any hit → do not use `no-helpers`**; fall back to +`no-dark-mode` or Lever 2. The bestax extras helpers (`is-cursor-*`, sizing) are dropped too. + +## Lever 2 — modular Sass build + +Compile only the Bulma modules + bestax extras partials the app actually uses. Needs the +`sass` compiler as a dev dependency (Bulma's own build tool — Vite compiles `.scss` natively): + +```sh +npm install -D sass +``` + +Create `src/styles.scss` — base + themes always come first: + +```scss +// Configure shared variables FIRST (before anything loads utilities) — +// the prebuilt flavors set this brand primary; omit it and buttons revert +// to Bulma's default turquoise: +@use 'bulma/sass/utilities' with ( + $primary: #1e6b99 +); + +// Required base: reset + CSS variable definitions +@use 'bulma/sass/base'; +@use 'bulma/sass/themes'; + +// One line per stock Bulma component the app imports… +@use 'bulma/sass/elements/button'; +@use 'bulma/sass/components/navbar'; +// …and per bestax extras component: +@use '@allxsmith/bestax-bulma/scss/components/dialog'; +// Helper categories only if the app uses those helper props: +@use 'bulma/sass/helpers/spacing'; +``` + +Then replace the prebuilt CSS import in `src/main.tsx` with `import './styles.scss';`, +build, and measure. Derive the `@use` list from the components the app imports from +`@allxsmith/bestax-bulma` — the full component→partial mapping, the authoritative extras +partial inventory, and a worked example are in `references/modular-build.md`. + +## Lever 3 — import & icon-asset hygiene (minor) + +- **Named imports.** `import * as Bestax from '@allxsmith/bestax-bulma'` defeats tree + shaking. Convert to named imports (`import { Button, Card } from …`) — a JS-side saving + (whole library ≈ 49 KB min+gzip), so report it honestly as minor. +- **Unused icon libraries.** Scaffolded apps may carry an icon library the app never uses: + icon-font packages in `package.json` (`@fortawesome/fontawesome-free`, `@mdi/font`, + `material-icons`, `material-symbols`) with their CSS imports in `src/main.*`, or Ionicons + CDN `