Files
nativewind/apps/website/docs/quick-starts/create-react-native-app.md
2022-10-25 08:47:30 +10:00

1.6 KiB

import StartCoding from "../_start-coding.md"

Create React Native App

1. Create a new React Native application

npx create-react-native-app my-nativewind-app

Choose "Default new app" and then move into the project's directory.

cd my-nativewind-app

You will need to install nativewind and it's peer dependency tailwindcss.

yarn add nativewind
yarn add --dev tailwindcss

2. Setup Tailwind CSS

:::caution

Do not set your content to ./**/*! This will cause Tailwind CLI to scan every file in your node_modules. For the fastest builds, be as specific as possible.

:::

Run npx tailwindcss init to create a tailwind.config.js file

Add the paths to all of your component files in your tailwind.config.js file.

// tailwind.config.js
+ const nativewind = require("nativewind/tailwind")

module.exports = {
- content: [],
+ content: ["./App.{js,jsx,ts,tsx}", "./screens/**/*.{js,jsx,ts,tsx}"],
  theme: {
    extend: {},
  },
  plugins: [],
+ presets: [nativewind]
}

3. Add the Babel preset

Modify your babel.config.js

// babel.config.js
module.exports = {
-   presets: ["babel-preset-expo"],
+   presets: ["babel-preset-expo", "nativewind/babel"],
};

4. Modify the Metro config

// metro.config.js
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require("expo/metro-config");
+ const withNativewind = require("nativewind/metro")

- module.exports = getDefaultConfig(__dirname)
+ module.exports = withNativewind(getDefaultConfig(__dirname))