Overview
The Luau output format generates a.luau module file that exports a factory function for creating Roblox StyleSheet instances. This is the default and recommended output format for rbx-css.
When to use Luau output
- Default choice: Best for most use cases
- Runtime creation: When you need to create StyleSheets programmatically at runtime
- Type safety: Works seamlessly with Luau type checking
- Minification: Supports minified output for production
- Rojo integration: Works perfectly with Rojo workflows
- Version control: Plain text format is easy to diff and review
Generated structure
The generated Luau module follows this structure:Module components
Factory function
The module exports acreateStyleSheet() function that returns a fully configured StyleSheet instance:
Root StyleSheet
Creates the rootStyleSheet instance and sets its name:
Design tokens
CSS custom properties from:root become StyleSheet attributes:
Style rules
Each CSS rule becomes aStyleRule instance with proper scoping:
SetProperty() for efficiency:
Pseudo-instance rules
CSS properties that map to Roblox pseudo-instances (likeborder-radius → UICorner) generate separate rules:
Theme support
When your CSS includes themes, the module generates theme StyleSheets and a helper function:Example output
Given this CSS input:/home/daytona/workspace/source/src/codegen/luau.ts
Value serialization
The Luau codegen serializes CSS values to Roblox types:Color3
UDim and UDim2
Numbers
Booleans
Enums
Fonts
ColorSequence
Two-stop gradients use the shorthand constructor:Token references
CLI usage
Output to file
Output to stdout
Minified output
Custom StyleSheet name
Programmatic API
Source file tracking
When using the CLI with-o, the generated file includes a source comment:
sourceFile option: