Getting Started
Load only the CSS you use
By default an app loads the CSS of every Nexub component, whether it uses 15 of them or all 150. From 12.1 a Tailwind 4 app can load only what its components need. It is opt-in: nothing changes until you switch.
| A typical page (15 components) | gzip |
|---|---|
@nexub/react/styles.css | 43.5 kB |
| Tailwind 4 with every @nexub dist folder scanned (the setup before 12.1) | about 42 kB |
| base-lean and the generated list | 26.7 kB |
…then --prune after the build | 21.2 kB |
CI keeps the last line under 21.9 kB, half of the 11.6 budget for styles.css, for the page in scripts/fixtures/css-page. A larger app saves less: an admin app that imports 66 components went from 43.6 kB to 32.5 kB.
1. Load the lean base
@nexub/themes/base and /core carry the CSS of components that only some apps use: the drawer, charts, Aurora, Celebrate, the dialog surfaces and more. base-lean and core-lean are the same files without them: tokens, resets, the focus ring, motion and density.
/* before */
@import '@nexub/themes/base' layer(base);
@source "../node_modules/@nexub/react/dist";
@source "../node_modules/@nexub/patterns/dist";
/* after */
@import '@nexub/themes/base-lean' layer(base); /* or core-lean, if you used core */
@import './nexub.css'; /* step 2 writes this file */2. Generate the list
nexub-usage --css reads your imports from @nexub/react, @nexub/patterns and @nexub/marketing, follows each component to the files it uses, and writes one CSS file: the component parts they need from @nexub/themes/parts, and an @source line for each of those files, so Tailwind generates only their classes. It also adds a part when your own code uses one of its classes, such as nx-stagger or nx-sheen.
npx -p @nexub/tokens nexub-usage src --css src/nexub.css # write it
npx -p @nexub/tokens nexub-usage src --css src/nexub.css --check # CI: fail if it is staleRun it again when you import a component you didn’t use before, or add the --check line to CI so a stale list fails the build instead of leaving a component unstyled.
3. Prune after the build (optional)
Tokens define about 1,100 custom properties and a page reads about half. After your build, --prune removes the Nexub ones that neither your CSS nor your JavaScript names:
npx -p @nexub/tokens nexub-usage --prune .next/static/css --js .next/static- It only removes properties that
@nexub/tokensor@nexub/themesdefine, never your own. - A property stays when any stylesheet or script names it, when a kept property’s value uses it, or when code builds names from its prefix (
`--motion-spring-${speed}`keeps every--motion-spring-*). - It can’t see a name that comes whole from data, such as
'--' + name. Keep the prefix in your code ('--color-' + toneor`var(--color-${tone})`keep every--color-*), or skip this step.
Without Tailwind
@nexub/react/styles.css stays one file with every component. See Use without Tailwind.