CSS distribution build
The CSS distribution build turns source styles into browser-ready stylesheets for package and CDN users. It produces full and minimal variants in readable and minified forms, then creates compatibility names for the main stylesheet so consumers can use stable asset paths.
Build model
The build has two source entrypoints with different goals. The full entrypoint assembles the shared reset rules, while the minimal entrypoint provides a smaller reset for consumers who need a narrower style set.
Source entrypoints
home/…/build-css.js maps src/index.css to the full asset family and src/mini.css to the minimal asset family. These entrypoints keep the choice of reset scope at the source level. The build carries that choice into matching index and mini distribution assets.
References: scripts/build-css.js• L13-16
Build stages
The build:css command processes each source entrypoint for the browser targets selected from the repository browsers list. It writes one readable asset and one minified asset for each entrypoint. The post-build hook then creates the compatibility aliases, while the complete build command checks the compressed size budgets.
The sequence below shows how both source variants become distribution assets and how the main aliases are added at the end.
flowchart LR
A[Full CSS source] --> C[Full readable CSS]
A --> E[Full minified CSS]
B[Minimal CSS source] --> D[Minimal readable CSS]
B --> F[Minimal minified CSS]
C --> G[CSS aliases]
E --> G
The stages are coupled by file names. The alias step reads the canonical full minified asset, so a source change reaches every published form only when the CSS build and the alias step both run.
References: package.json• L50-56 scripts/build-css.js• L8-31
Distribution variants
The build exposes four primary assets: full readable CSS, full minified CSS, minimal readable CSS, and minimal minified CSS. Readable assets support inspection and local use. Minified assets reduce transfer size for production use.
The full and minimal variants share the same processing path but do not share the same source rules. This lets a consumer select reset coverage without changing the distribution contract.
References: scripts/build-css.js• L13-16 package.json• L8-14
Asset exposure
The generated files form the package’s CSS surface. The package metadata includes the distribution, alias, and source trees, while the default package stylesheet points to the full minified asset. The CSS artifact publishing page explains the checked-in assets and their consumer-facing role.
Package entrypoints
Package consumers receive the full minified stylesheet through the package’s default main and style entries. The package also exposes the minimal variant and direct paths for the readable, minified, and alias assets.
This separation keeps the default install path small and direct while preserving access to the other supported forms of the stylesheet.
References: package.json• L6-17 package.json• L37-41
Alias outputs
After the CSS build, the alias step copies the canonical full minified file to both css/reseter.min.css and css/reseter.css. These aliases provide familiar names without creating a second stylesheet source or a second transformation path.
The CSS alias copy automation page describes this final copy step and its source-to-target contract.
References: package.json• L51-56 scripts/copy-css-aliases.js• L6-18
Build safeguards
The distribution process checks asset size after it creates the files. Bundlewatch measures Brotli-compressed output against separate limits for full and minimal readable and minified assets.
These limits protect the role of the build as a small browser reset. A size increase can fail the final build even when the CSS remains valid, which makes the change visible before distribution.
References: .bundlewatch.config.js• L1-22 package.json• L53-54
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the full and minimal source entrypoints aligned with the
indexandminioutput names. - Keep browser-target selection and minification attached to both variants when changing the CSS build.
- Keep the alias sources pointed at the canonical full minified asset when changing distribution names.
- Keep package
main,style, and export entries aligned with the asset that consumers should load by default. - Recheck the Brotli size budgets when source rules or build transforms change.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A source change is followed by only a partial build | Checked-in or published CSS can remain stale | Run the complete build pipeline |
| An output name changes without updating package metadata | Package consumers can receive a missing default stylesheet | Keep main, style, exports, and generated paths aligned |
| The alias copy runs before dist/index.min.css exists | Alias creation fails or uses old output | Keep alias copying after the CSS build |
| A rule increase exceeds its Brotli budget | The build fails its size check | Review the size limits and the CSS change together |
Key files
| File | Why to read it |
|---|---|
| package.json | Defines the CSS build order, package entrypoints, and published paths |
| scripts/build-css.js | Defines the full and minimal source-to-distribution asset build |
| scripts/copy-css-aliases.js | Defines the compatibility alias contract |
| .bundlewatch.config.js | Defines the compressed size checks for distribution assets |