Babel Configuration
CSSX uses a Babel preset to transform styles at build time.
cssxjs/babel
The Babel preset that transforms CSSX syntax.
Options
Example Configuration
Platform Detection
The platform option is typically set automatically based on your bundler configuration:
- React Native / Expo: Set via Metro bundler
- Web: Defaults to
'web'
You can also set platform-specific variables in your Stylus code:
Caching
When cache: 'teamplay' is set (or auto-detected), the Babel transform generates code that integrates with teamplay for optimized style memoization.
See the Caching guide for more details.
What Gets Transformed
The Babel preset transforms:
styltemplate literals → Compiled style objectscsstemplate literals → Compiled style objectspugtemplate literals → JSX elements (if enabled)styleNameprops → Connected to compiled stylespartprops → Part style injection points
Before Transform
After Transform
The Babel preset converts this into optimized runtime code that:
- Compiles Stylus to style objects at build time
- Connects
styleNameto the compiled styles - Injects part style props automatically
TypeScript
CSSX works with TypeScript. The styl and pug template literals are removed at compile time, so no runtime types are needed.
For styleName prop typing, you may need to extend JSX types in your project.