To create a new Expo app using the TypeScript template, run the following command:
yarn create expo-app --templateInstall the necessary TypeScript dependencies:
yarn add --dev @tsconfig/react-native @types/jest @types/react @types/react-test-renderer typescript
yarn add expo react-native-web react-dom @expo/webpack-configStart your Expo project using the tunnel option:
yarn expo start --tunnelTo set up navigation in your app, follow these steps:
yarn add @react-navigation/nativeyarn add react-native-screens react-native-safe-area-context @react-navigation/native-stack @react-navigation/stackIf you want to use bottom tabs navigation, install the following package:
yarn add @react-navigation/bottom-tabsSet up ESLint and Prettier for your project:
yarn add -D expo eslint eslint-config-prettier eslint-config-universe eslint-plugin-react-hooks @typescript-eslint/eslint-plugin @typescript-eslint/parserIn your package.json, update the eslintConfig section to extend the desired ESLint configuration:
{
"eslintConfig": {
"extends": "universe/native"
}
}Create an .eslintrc.json file and extend the ESLint configurations:
{
"extends": ["universe", "plugin:react-hooks/recommended"]
}Install Prettier
yarn add expo prettierTo enable viewport units in your styles, install the react-native-viewport-units package:
yarn add react-native-viewport-units --saveImport the units in your code:
var { vw, vh, vmin, vmax } = require('react-native-viewport-units');Choose between Nativewind or Tailwind-RN based on your preference and project requirements.
yarn add nativewind postcss autoprefixer
yarn add --dev tailwindcss@3.3.2Run the following command to initialize Tailwind CSS and create the tailwind.config.js file:
npx tailwindcss initEdit your tailwind.config.js file to include paths to your component files:
module.exports = {
- content: [],
+ content: ["./App.{js,jsx,ts,tsx}", "./src/**/*.{js,jsx,ts,tsx}" "./<custom directory>/**/*.{js,jsx,ts,tsx}", ],
theme: {
extend: {},
},
plugins: [],
}Modify your babel.config.js to include the Nativewind Babel plugin:
module.exports = function (api) {
api.cache(true);
return {
presets: ["babel-preset-expo"],
+ plugins: ["nativewind/babel"],
};
};Create a postcss.config.js file and add the following configuration:
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
}
}Create a metro.config.js file and add the following code to enable CSS support in Metro:
const { getDefaultConfig } = require('expo/metro-config');
const config = getDefaultConfig(__dirname, {
isCSSEnabled: true,
});
module.exports = config;Create a globals.css file and add the following Tailwind CSS imports:
@tailwind base;
@tailwind components;
@tailwind utilities;Import the globals.css file in your project where needed.
If you are using TypeScript, create a globals.d.ts file and add the following reference:
/// <reference types="nativewind/types" />yarn add tailwind-rnnpx setup-tailwind-rnFollow the configuration steps as described in the terminal, and run:
yarn dev:tailwindNote: Keep the dev server running at all times.
In your input.css file, include the following Tailwind CSS imports:
@tailwind base;
@tailwind components;
@tailwind utilities;In your tailwind.config.js file, specify the content paths for your project.
This completes the setup for Tailwind CSS in your React Native project. 👍