Prerequisites
Before installing styled-static, ensure you have:React 19+
styled-static requires React 19 or later for automatic ref forwarding
Vite
Vite 5.0+ is required for the build-time transformation
Install the Package
Choose your preferred package manager and run the installation command:Configure the Vite Plugin
Add the styled-static plugin to yourvite.config.ts file. The plugin must be placed before the React plugin in the plugins array.
Plugin Order Matters — The styled-static plugin must come before the React plugin. This ensures proper transformation of styled components.
Optional: Lightning CSS
For better performance and automatic vendor prefixes, install Lightning CSS:Configuration Options
The styled-static plugin accepts the following options:Prefix for generated class names. Useful for avoiding conflicts in microfrontends or component libraries.
Controls how CSS is output:
'auto'— Uses'file'for library builds (build.libset),'virtual'for apps'virtual'— CSS as virtual modules (Vite bundles into single file)'file'— CSS as separate files co-located with JS (enables tree-shaking for libraries)
Enable debug logging. Set to
true or use DEBUG_STYLED_STATIC=true env var.Verify Installation
Create a simple test component to verify everything is working:Installation complete! You’re ready to start using styled-static. Continue to the Quick Start guide to learn more.
Troubleshooting
Error: 'styled' was not transformed at build time
Error: 'styled' was not transformed at build time
This error means the Vite plugin isn’t configured correctly. Check that:
- The styled-static plugin is in your
vite.config.ts - It’s placed before the React plugin
- You’re importing from the correct package:
@alex.radulescu/styled-static
Storybook: 'This package is ESM only'
Storybook: 'This package is ESM only'
If using styled-static with Storybook, add it to
optimizeDeps.include:.storybook/main.ts
Type errors with React 19
Type errors with React 19
Ensure you have React 19+ installed:
Next Steps
Quick Start
Build your first styled component with a complete example
Core API
Learn about the styled API and all its features
TypeScript Support
Explore TypeScript features and type inference
Configuration
Deep dive into plugin configuration options