|
| 1 | +import { PackageManagerTabs } from 'rspress/theme'; |
| 2 | + |
| 3 | +# NativeWind |
| 4 | + |
| 5 | +[NativeWind](https://www.nativewind.dev/) brings Tailwind CSS utility classes to React Native, enabling rapid, consistent styling. With Re.Pack, you can seamlessly integrate NativeWind through a dedicated plugin. |
| 6 | + |
| 7 | +[@callstack/repack-plugin-nativewind](https://github.com/callstack/repack/tree/main/packages/plugin-nativewind) is a plugin for Re.Pack that enables integrating NativeWind into your React Native projects. |
| 8 | + |
| 9 | +## About |
| 10 | + |
| 11 | +This plugin seamlessly integrates NativeWind with Re.Pack's build process by: |
| 12 | + |
| 13 | +- Configuring PostCSS and Tailwind CSS processing for your stylesheets |
| 14 | +- Handling conversion of CSS to React Native-compatible styles |
| 15 | +- Setting up proper SWC transformations for NativeWind's JSX runtime |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +First, follow these steps from the official [NativeWind installation guide](https://www.nativewind.dev/docs/getting-started/installation): |
| 20 | + |
| 21 | +1. [Install NativeWind](https://www.nativewind.dev/docs/getting-started/installation#1-install-nativewind) |
| 22 | +2. [Setup Tailwind CSS](https://www.nativewind.dev/docs/getting-started/installation#2-setup-tailwind-css) |
| 23 | +3. [Import your CSS file](https://www.nativewind.dev/docs/getting-started/installation#5-import-your-css-file) |
| 24 | +4. (Optional) [Setup TypeScript support](https://www.nativewind.dev/docs/getting-started/installation#7-typescript-setup-optional) |
| 25 | + |
| 26 | +Then install the Re.Pack NativeWind plugin and its dependencies: |
| 27 | + |
| 28 | +<PackageManagerTabs command="install -D @callstack/repack-plugin-nativewind postcss postcss-loader autoprefixer" /> |
| 29 | + |
| 30 | +:::tip Version Alignment |
| 31 | +The NativeWind plugin is versioned together with Re.Pack. For best compatibility, align the version of `@callstack/repack-plugin-nativewind` with your `@callstack/repack` version in the project. |
| 32 | +::: |
| 33 | + |
| 34 | +:::info{title="A note on dependencies:"} |
| 35 | +These additional dependencies (`postcss`, `postcss-loader`, and `autoprefixer`) are required for processing Tailwind CSS with Webpack/Rspack, as specified in the [official Tailwind CSS Rspack guide](https://tailwindcss.com/docs/guides/rspack). They enable PostCSS processing and autoprefixing of CSS styles in your build pipeline. |
| 36 | +::: |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +:::info{title="Webpack specific configuration"} |
| 41 | +If you are using Webpack (not Rspack), you need to add the following configuration to your `babel.config.js`: |
| 42 | + |
| 43 | +```js title="babel.config.js" |
| 44 | +plugins: [ |
| 45 | + [ |
| 46 | + '@babel/plugin-transform-react-jsx', |
| 47 | + { |
| 48 | + runtime: 'automatic', |
| 49 | + importSource: 'nativewind', |
| 50 | + }, |
| 51 | + ], |
| 52 | +], |
| 53 | +``` |
| 54 | +::: |
| 55 | + |
| 56 | +### Plugin |
| 57 | + |
| 58 | +To add the plugin to your Re.Pack configuration, update your `rspack.config.js` or `webpack.config.js` as follows: |
| 59 | + |
| 60 | +```js title="rspack.config.js" |
| 61 | +import { NativeWindPlugin } from "@callstack/repack-plugin-nativewind"; |
| 62 | + |
| 63 | +export default (env) => { |
| 64 | + // ... |
| 65 | + return { |
| 66 | + // ... |
| 67 | + plugins: [ |
| 68 | + // ... |
| 69 | + new NativeWindPlugin(), |
| 70 | + ], |
| 71 | + }; |
| 72 | +}; |
| 73 | +``` |
| 74 | + |
| 75 | +## Troubleshooting |
| 76 | + |
| 77 | +- **Styles not applying?** |
| 78 | + |
| 79 | + Ensure your CSS import is present and the plugin is added to your config. |
| 80 | + |
| 81 | +- **PostCSS errors?** |
| 82 | + |
| 83 | + Double-check that all required dependencies are installed and your `postcss.config.js` is set up. |
| 84 | + |
| 85 | +- **TypeScript issues?** |
| 86 | + |
| 87 | + Follow the [NativeWind TypeScript setup guide](https://www.nativewind.dev/getting-started/typescript). |
| 88 | + |
| 89 | +## Further Resources |
| 90 | + |
| 91 | +- [NativeWind Documentation](https://www.nativewind.dev/docs) |
| 92 | +- [Tailwind CSS Documentation](https://tailwindcss.com/) |
| 93 | +- [Re.Pack NativeWind Plugin Repo](https://github.com/callstack/repack/tree/main/packages/plugin-nativewind) |
| 94 | + |
0 commit comments