CLI — Rails, Django, Laravel, PHP
Build a static nib.css with the CLI and use NibCSS from any server-rendered framework, with no bundler involved.
Not every project has a JavaScript build. The CLI scans whatever files you point it at — ERB, Blade,
Django templates, plain HTML, even .js strings — and writes a stylesheet you link like any other.
1. Install#
npm i @nibcss/runtime
npm i -D @nibcss/clinpx nib init # writes a fully commented nibcss.config.ts2. Build the stylesheet#
npx nib build -o assets/nib.css --content "**/*.html"
npx nib watch -o assets/nib.css --content "**/*.html" # and rebuild on changeAs scripts:
{
"scripts": {
"nib": "nib watch -o assets/nib.css --content \"**/*.{html,js}\"",
"build": "nib build -o assets/nib.css --content \"**/*.{html,js}\" --minify"
}
}Command | What it does |
|---|---|
| create |
| scan once, write the stylesheet and the config files |
| the same, then rebuild on every change (about 50 ms) |
Flag | Default | What it does |
|---|---|---|
|
| where the stylesheet goes; the config files are written beside it |
| project sources | globs to scan, repeatable; |
| off | strip comments and whitespace |
| auto-detected | a config file somewhere else |
Scanning .js as well as your templates is worth it: attributes inside strings your scripts inject
end up in the stylesheet too. Anything containing ${…} is left to the runtime, as it must be.
Three files are written beside each other:
File | For |
|---|---|
| the stylesheet — link it |
| sets |
| the same data as a module, plus |
3. The page#
<head>
<link rel="stylesheet" href="assets/nib.css" />
<script src="assets/nib.config.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@nibcss/runtime"></script>
</head>From node_modules instead of a CDN: <script src="node_modules/@nibcss/runtime/dist/nib.global.js"></script>.
4. Rails, Django, Laravel#
nib watch -o app/assets/stylesheets/nib.css --content "app/views/**/*.erb"<%# app/views/layouts/application.html.erb %>
<%= stylesheet_link_tag "nib" %>
<script src="/assets/nib.config.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@nibcss/runtime"></script>Run nib watch beside the framework's own dev server; it has nothing to coordinate with.
5. What you give up, and what you do not#
CLI | bundler plugin | |
|---|---|---|
Classes in the HTML the server sends | no — the runtime adds them | yes, compiled in |
Styled before the first paint | yes, with the runtime tag synchronous in | yes |
JavaScript required | yes | only for dynamic values |
Live rebuild |
| applied without a reload |
Diagnostics | terminal (file and line) + | the same, plus the overlay |
6. The browser API#
window.Nib is the runtime: classesFor(attr), toggleDarkMode(), darkMode.isDark(),
configure(partial), engine.config, engine.stats(), flush(), and NibRuntime for a
second instance scoped to a subtree.
Common pitfalls#
- Linking
nib.cssbut notnib.config.js— with a customprefixnothing matches. - A
--contentglob that misses a template directory: those attributes are simply not in the stylesheet, and only the runtime saves them. - Running
nib buildin CI but committing a stalenib.css— build it in the pipeline instead. defer/asyncon the runtime tag.