Guide

Stylesheet size and budgets

Every Styloviz component is styled with Tailwind CSS utilities, so Tailwind writes CSS for the files it scans. What it scans decides how big your stylesheet is, and Angular's build budgets count it. This page shows how to make an app pay only for the components it uses, and how to keep it that way.

What ng add writes

ng add @styloviz/core ends by running ng g @styloviz/core:sources. It follows your app's imports into the installed kit packages and writes two marked blocks into your global stylesheet: the parts of the kit stylesheet your code uses, and one @source line per kit file your imports reach. For the demo page ng add creates, it looks like this:

@import 'tailwindcss' source(none);
/* styloviz:parts start — … */
@import '@styloviz/core/styles/parts/tokens.css';
@import '@styloviz/core/styles/parts/base.css';
@import '@styloviz/core/styles/parts/date-input.css';
/* styloviz:parts end */
/* styloviz:sources start — … */
@source "./";
@source "../public";
@source "../node_modules/@styloviz/button/fesm2022/styloviz-button.mjs";
@source "../node_modules/@styloviz/core/fesm2022/styloviz-core-dev.mjs";
…
@source "../node_modules/@styloviz/icons/fesm2022/glyph/info.mjs";
@source "../node_modules/@styloviz/icons/fesm2022/styloviz-icons-core.mjs";
/* styloviz:sources end */

The parts block replaces the single styloviz.css import: the glow, the four preset themes and each component's animations are parts of their own, imported only when your code or a listed kit file uses them, in the order styloviz.css has them. The sources block also lists what Tailwind used to find by itself: your source root, every library project's source root, the build's asset folders, and app files imported from outside them. Do not edit between the markers; the next run rewrites them.

Keep the list up to date

The list knows only the imports your app had when it was written. After you import another kit component, run it again:

ng g @styloviz/core:sources            # the kit files your imports reach
ng g @styloviz/core:sources --check    # in CI: fail when the list is out of date
ng g @styloviz/core:sources --all      # back to scanning every installed kit package

A component whose file is missing from the list renders without its styles. In a development build it says so in the console — a [styloviz] warning that names the entry point and this command — so you notice on your own machine, not in production. --check writes nothing and fails when the list is out of date, which makes it the line to add to CI.

Why the Tailwind import says source(none)

By default @import "tailwindcss" scans the whole workspace, and Tailwind then reads a file listed inside node_modules as its whole package: any other source that contains node_modules widens every line of the list back to the package it is in, and the list saves nothing. With source(none) nothing is scanned unless a line names it, which is why the block lists your own folders too. Keep it, and never add an @source for a folder that contains node_modules (the workspace root, for instance) — the schematic warns when it finds one. It also refuses a source root that contains node_modules; move that code into a folder of its own.

Your own folders and class names

Lines you add yourself go outside the block, where the schematic leaves them alone. Two cases need one: a folder of your own that Angular's workspace does not list (a shared package linked from elsewhere), and a class name your code builds from pieces at run time, such as 'bg-' + tone + '-600'. No scan has ever found the second kind; list the finished names with @source inline. The kit itself writes every class name out in full, so this is only about your code.

/* styloviz:sources end */

/* Your own lines go outside the block. */
@source "../../shared-ui/src";
@source inline("bg-danger-600 bg-accent-600 bg-warning-600");

Exact: what the build ships

Following imports is a safe superset: a component you import but never put in a template is still listed. --from-build lists instead the kit files your last production build actually shipped, read from its stats (lazy chunks and the server build included):

ng build --stats-json
ng g @styloviz/core:sources --from-build

# in CI, after the same build:
ng g @styloviz/core:sources --from-build --check

It refuses stats older than your code or your install, so build first. --stats <file> names the stats file when it is not in the app's output folder. Kit code that runs only in development is not in a production build, so it drops out of this list; none of it draws anything today. A shipped file the import walk did not reach is kept and reported.

Budgets

A new Angular app warns when its initial bundle passes 500 kB and fails the build at 1 MB. The budget counts raw bytes; this CSS compresses about 14 to 1, so a visitor downloads far less, but the build still fails. Measured on fresh ng new apps, Angular 22.2, production builds:

AppInitial bundleDefault budgets
The ng add demo page, every free package scanned (ng add in 2.0.2 and earlier)667 kBover the 500 kB warning
The same with Pro installed and both broad lines919 kBover the warning, 81 kB from the 1 MB error
The ng add demo page as ng add leaves it now280 kBwithin both
A typical admin app — 15 families, Pro charts and table — every package scanned970 kBover the warning
The same app with the exact list469 kBwithin both

For the demo page the stylesheet itself goes from 434 kB to 47 kB. The JavaScript does not change: the difference is all stylesheet. Each kit file in the list adds one small rule for the development check, about 85 bytes. Raising the budget makes the warning go away and keeps the cost; the list removes the cost.

Without ng add

Set up by hand, the stylesheet starts with the broad lines, which scan every installed kit package. They work, and they are what --all writes back:

@import "tailwindcss";
@import "@styloviz/core/styles/styloviz.css";
@source "../node_modules/@styloviz";
@source "../node_modules/@styloviz-pro";   /* Pro only */

Then run ng g @styloviz/core:sources once to replace them with the exact list. The full setup is on the Getting started page.