|
| 1 | +import { PackageManagerTabs } from 'rspress/theme'; |
| 2 | + |
| 3 | +# Expo |
| 4 | + |
| 5 | +::: warning |
| 6 | +Re.Pack adds minimal support for Expo managed projects. Since Re.Pack replaces Metro, some Expo features may not work as expected. Please refer to the [limitations section](#limitations) for more details. |
| 7 | +::: |
| 8 | + |
| 9 | +[Expo](https://docs.expo.dev/) is a popular framework for building React Native applications. Re.Pack provides a plugin to integrate with Expo managed projects, allowing you to leverage Re.Pack's bundling capabilities while still using Expo's features. |
| 10 | + |
| 11 | +Using Expo with Re.Pack requires some setup - this guide will show you how to get started with Expo in your project. |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +### 1. Install Expo Package |
| 16 | + |
| 17 | +Install the Expo package in your project: |
| 18 | + |
| 19 | +<PackageManagerTabs command="install expo" /> |
| 20 | + |
| 21 | +### 2. Add Re.Pack Integration |
| 22 | + |
| 23 | +First, install the official Re.Pack Expo plugin: |
| 24 | + |
| 25 | +<PackageManagerTabs command="install -D @callstack/repack-plugin-expo" /> |
| 26 | + |
| 27 | +Then, add the plugin to your configuration file: |
| 28 | + |
| 29 | +```js title=rspack.config.cjs |
| 30 | +const { ExpoPlugin } = require("@callstack/repack-plugin-expo"); |
| 31 | + |
| 32 | +module.exports = { |
| 33 | + plugins: [ |
| 34 | + new ExpoPlugin(), |
| 35 | + ] |
| 36 | +}; |
| 37 | +``` |
| 38 | + |
| 39 | +### 3. Modify CNG Configuration |
| 40 | + |
| 41 | +::: info |
| 42 | +This step is crucial as it ensures that React Native CLI will be used when building for production instead of Expo CLI, which is not compatible with Re.Pack. |
| 43 | +::: |
| 44 | + |
| 45 | +Modify your `app.json` or `app.config.js` to include the following configuration: |
| 46 | + |
| 47 | +```jsonc title=app.json |
| 48 | +{ |
| 49 | + // ... |
| 50 | + "plugins": [ |
| 51 | + "@callstack/repack-plugin-expo/plugin" |
| 52 | + ] |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +## Usage |
| 57 | + |
| 58 | +After completing the setup, you can start using Re.Pack in your Expo application. |
| 59 | + |
| 60 | +### Generating the Development Build |
| 61 | + |
| 62 | +To generate a development build of your Expo application, run the following command: |
| 63 | + |
| 64 | +<PackageManagerTabs command="expo prebuild" /> |
| 65 | + |
| 66 | +### Development Workflow |
| 67 | + |
| 68 | +After running this command, you can develop using the default Re.Pack workflow. |
| 69 | + |
| 70 | +## Expo Router Support |
| 71 | + |
| 72 | +`@callstack/repack-plugin-expo` has built-in support for [Expo Router](https://expo.github.io/router/docs). |
| 73 | + |
| 74 | +### 1. Install Expo Router |
| 75 | + |
| 76 | +If you haven't already, install the Expo Router and its dependencies: |
| 77 | + |
| 78 | +<PackageManagerTabs command="expo install expo-constants expo-router expo-linking expo-status-bar react-native-screens react-native-safe-area-context" exec /> |
| 79 | + |
| 80 | +### 2. Modify CNG Configuration |
| 81 | + |
| 82 | +Add `expo-router` to the plugins array in your `app.json` or `app.config.js` along with the Re.Pack plugin: |
| 83 | + |
| 84 | +```jsonc title=app.json |
| 85 | +{ |
| 86 | + // ... |
| 87 | + "plugins": [ |
| 88 | + "expo-router", |
| 89 | + "@callstack/repack-plugin-expo/plugin" |
| 90 | + ] |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +### 3. Modify Re.Pack Integration |
| 95 | + |
| 96 | +Modify the plugin configuration in your `rspack.config.cjs` to enable the router support: |
| 97 | + |
| 98 | +```js title=rspack.config.cjs |
| 99 | +const { ExpoPlugin } = require("@callstack/repack-plugin-expo"); |
| 100 | + |
| 101 | +module.exports = { |
| 102 | + plugins: [ |
| 103 | + new ExpoPlugin({ router: true }), |
| 104 | + ] |
| 105 | +}; |
| 106 | +``` |
| 107 | + |
| 108 | +You can also customize the base URL and root directory for the router: |
| 109 | + |
| 110 | +```js title=rspack.config.cjs |
| 111 | +const { ExpoPlugin } = require("@callstack/repack-plugin-expo"); |
| 112 | + |
| 113 | +module.exports = { |
| 114 | + plugins: [ |
| 115 | + new ExpoPlugin({ |
| 116 | + router: { baseUrl: '/some-base-url', root: './src/screens' } |
| 117 | + }), |
| 118 | + ] |
| 119 | +}; |
| 120 | +``` |
| 121 | + |
| 122 | +### 4. Change Your Application Entry Point |
| 123 | + |
| 124 | +::: danger |
| 125 | +Do not use `expo-router/entry` as your entry point when using Re.Pack. This entry point is designed to work with Metro bundler and may not function correctly with Re.Pack. |
| 126 | +::: |
| 127 | + |
| 128 | +Change your application entry point to use the router's `ExpoRoot` component. Update your `App.js` as follows: |
| 129 | + |
| 130 | +```jsx title=App.js |
| 131 | +import { ExpoRoot } from 'expo-router'; |
| 132 | +import { ctx } from 'expo-router/_ctx'; |
| 133 | + |
| 134 | +export default function Application() { |
| 135 | + return <ExpoRoot context={ctx} />; |
| 136 | +} |
| 137 | +``` |
| 138 | + |
| 139 | +## Limitations |
| 140 | + |
| 141 | +When using Re.Pack with Expo managed projects, there are some limitations to be aware of: |
| 142 | + |
| 143 | +- Expo CLI: Expo commands that rely on Metro bundler (like `expo start`, `expo run android` and `expo run ios`) will not work as expected. Use React Native CLI commands instead (e.g., `npx react-native start`, `npx react-native run-android`, `npx react-native run-ios`). |
| 144 | +- Expo Go: Re.Pack does not support running in Expo Go. You will need to do a development build to test your application. |
| 145 | +- EAS: Expo EAS doesn't allow custom bundlers, so you cannot use Re.Pack with EAS Build at the moment. |
| 146 | +- Expo Updates: Re.Pack does not support over-the-air updates with Expo Updates. You can use Remote Chunks though (see [code splitting](../features/code-splitting) for more details). |
| 147 | +- Type-safe routes: Re.Pack doesn't automatically generate type-safe `.d.ts` files for Expo Router. |
| 148 | +- Experimental RSC, server actions or API routes: These features are not supported in Expo managed projects with Re.Pack. |
0 commit comments