Overview
NativeWind provides a Babel plugin that transforms your styles at build time. This plugin is a thin wrapper aroundreact-native-css/babel that ensures optimal performance by processing CSS during compilation rather than at runtime.
The Babel plugin is typically configured automatically when using Expo. Manual configuration is only needed for custom setups or React Native CLI projects.
Installation
The Babel plugin is exported from thenativewind/babel package:
Configuration
The NativeWind Babel plugin re-exports thereact-native-css/babel plugin with all its functionality. It doesn’t add any additional configuration options but provides a consistent import path for NativeWind users.
Basic Setup
Add the plugin to yourbabel.config.js:
babel.config.js
With React Native CLI
babel.config.js
TypeScript Projects
babel.config.js
Environment-Specific Configuration
You can configure different behavior for development and production:babel.config.js
Plugin Order
babel.config.js
- NativeWind plugin - Early in the plugin list
- Transform plugins - Middle
- Reanimated plugin - Always last (if used)
How It Works
The Babel plugin performs several transformations at build time:- CSS Extraction - Extracts Tailwind classes from
classNameprops - Style Generation - Generates optimized StyleSheet objects
- Runtime Optimization - Reduces runtime CSS parsing overhead
- Type Safety - Works with TypeScript to provide type-safe styling
Testing Configuration
When running tests with Jest, ensure your Babel configuration applies:babel.config.js
Re-exported Functionality
Thenativewind/babel package re-exports all exports from react-native-css/babel:
Common Patterns
Monorepo Setup
babel.config.js
With Custom Transformers
babel.config.js
Troubleshooting
Styles not applying
- Verify the plugin is in your
babel.config.js - Clear Babel cache:
npx expo start --clear - Ensure preset order is correct
Build errors
If you encounter build errors:TypeScript errors
Ensure you have both:- Babel plugin configured
- Metro config with
withNativewind - TypeScript types generated (check for
nativewind-env.d.ts)
Performance Considerations
The Babel plugin performs heavy lifting at build time, not runtime. This means:
- Slower builds (one-time cost)
- Faster app performance (ongoing benefit)
- Smaller bundle size (optimized styles)
- Using persistent caching
- Enabling Babel’s cache:
api.cache(true) - Running builds in production mode for optimal output
Related
- Metro Configuration - Configure Metro bundler
- Tailwind Plugin - Configure Tailwind CSS plugin
- Installation Guide - Complete setup guide