compile() function is the core compiler that transforms CSS into rbx-css’s intermediate representation (IR). It parses CSS files, extracts tokens, maps selectors and properties to Roblox equivalents, and returns a structured StyleSheetIR object.
Signature
Parameters
Array of CSS source files to compile. Each object contains:
Compiler configuration options
Returns
Compilation result containing the IR, warnings, and metadata
Example
Compilation process
The compile function performs the following steps:- Parse CSS — All source files are parsed using lightningcss
- Extract tokens — CSS custom properties from
:rootare extracted as tokens - Extract themes — Theme-specific tokens from
[data-theme]or@media (prefers-color-scheme)are identified - Map selectors — CSS selectors are mapped to Roblox selector syntax (e.g.,
div→Frame) - Map properties — CSS properties are mapped to Roblox properties and pseudo-instances
- Generate base rules — Default element rules are prepended (unless
includeBaseRules: false) - Generate compound selectors — Width/height combinations are merged to fix Roblox’s single
Sizeproperty
Related
- generateLuau() — Generate Luau code from the IR
- generateRBXMX() — Generate RBXMX XML from the IR
- Types reference — Full type definitions