-
Notifications
You must be signed in to change notification settings - Fork 12
feat: adds release mode docs to repack doc #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Thegrep01
wants to merge
17
commits into
main
Choose a base branch
from
feat/rn-repack-release-doc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
dd4f6d9
feat: adds release mode docs to repack doc
4abd054
fix: changes without to with
44dd5af
Update start-from-scratch.mdx
Thegrep01 18ef207
feat: re-works flow
1e88200
Update components/zephyr/repack/start-from-scratch.mdx
Thegrep01 b2b4d8c
Update components/zephyr/repack/start-from-scratch.mdx
Thegrep01 414e929
Update components/zephyr/repack/start-from-scratch.mdx
Thegrep01 c6cd96d
fix: changes ending
bf84dc5
feat: adds extra explanation to ZC
dcc78d9
Update components/zephyr/repack/start-from-scratch.mdx
Thegrep01 7f27345
Update components/zephyr/repack/start-from-scratch.mdx
Thegrep01 4fcbd56
Update components/zephyr/repack/start-from-scratch.mdx
Thegrep01 8f73175
Update components/zephyr/repack/start-from-scratch.mdx
Thegrep01 8219f55
Update components/zephyr/repack/start-from-scratch.mdx
Thegrep01 dfd8b01
feat: moves doc to repack-mf
dd9a1be
Merge branch 'feat/rn-repack-release-doc' of https://github.com/Zephy…
854bf8e
Merge branch 'main' into feat/rn-repack-release-doc
zmzlois File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -536,4 +536,222 @@ You should see the applicaiton running in the iOS emulator: | |
|
||
<Image src="/host-app-ios.webp" alt="Zephyr Cloud Minimal example running in iOS emulator" /> | ||
|
||
The process should be the same for Android. | ||
The process should be the same for Android. | ||
|
||
## Running the application in release mode with Zephyr | ||
|
||
By default, the HostApp loads miniapp bundles from a local development server (e.g. localhost). To run the app in production/release mode without using the Zephyr development environment, you must replace those local URLs with the Zephyr Cloud URLs for each miniapp. This ensures the HostApp fetches the miniapp bundles directly from the Zephyr-hosted endpoints. The process involves configuring your Zephyr environment - and zephyr will auto-retrieving the correct remote URLs as well as updating the HostApp’s module federation configuration. Once completed, you can build and launch the app in release mode normally (e.g. via Xcode or react-native release build), and it will load miniapps from the Zephyr Cloud URLs instead of localhost. | ||
|
||
To successfully run the HostApp in release mode using Zephyr-hosted MiniApps, you need to have a Zephyr environment configured for your project (such as production or staging). Each MiniApps (remote module), along with the HostApp itself, must be registered within this environment. For step-by-step setup guidance, refer to the [Zephyr Environment Guide](../../how-to/environments.mdx) | ||
|
||
### Steps | ||
|
||
Follow these steps to configure and run the HostApp in release mode with Zephyr: | ||
|
||
Configure the Zephyr environment: | ||
|
||
1. Change your configs to divide debug builds and release builds: | ||
zmzlois marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- In the HostApp and MiniApp, change the `rspack.config.mjs` file to add a `ZC` variable: | ||
|
||
Thegrep01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```js title="HostApp/rspack.config.mjs"{9,17,72} | ||
import path from 'node:path'; | ||
import {fileURLToPath} from 'node:url'; | ||
import * as Repack from '@callstack/repack'; | ||
import {withZephyr} from 'zephyr-repack-plugin'; | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
|
||
const USE_ZEPHYR = Boolean(process.env.ZC); | ||
/** | ||
* Rspack configuration enhanced with Re.Pack defaults for React Native. | ||
* | ||
* Learn about Rspack configuration: https://rspack.dev/config/ | ||
* Learn about Re.Pack configuration: https://re-pack.dev/docs/guides/configuration | ||
*/ | ||
|
||
const config = env => { | ||
const { platform, mode } = env | ||
return { | ||
context: __dirname, | ||
entry: './index.js', | ||
resolve: { | ||
// 1. Understand the file path of ios and android file extensions | ||
// 2. Configure the output to be as close to Metro as possible | ||
...Repack.getResolveOptions(), | ||
}, | ||
output: { | ||
// Unsure - for module federation HMR and runtime? | ||
uniqueName: 'react-native-host-app', | ||
}, | ||
module: { | ||
rules: [ | ||
...Repack.getJsTransformRules(), | ||
...Repack.getAssetTransformRules(), | ||
], | ||
}, | ||
plugins: [ | ||
new Repack.RepackPlugin({ | ||
platform, | ||
}), | ||
new Repack.plugins.ModuleFederationPluginV2({ | ||
name: 'HostApp', | ||
filename: 'HostApp.container.js.bundle', | ||
dts: false, | ||
remotes: { | ||
MiniApp: `MiniApp@http://localhost:9001/${platform}/MiniApp.container.js.bundle`, | ||
}, | ||
shared: { | ||
react: { | ||
singleton: true, | ||
version: '19.0.0', | ||
eager: true, | ||
}, | ||
'react-native': { | ||
singleton: true, | ||
version: '0.78.0', | ||
eager: true, | ||
} | ||
}, | ||
}), | ||
// Supports for new architecture - Hermes can also use JS, it's not a requirement, it will still work the same but it's for performance optimization | ||
new Repack.plugins.HermesBytecodePlugin({ | ||
enabled: mode === 'production', | ||
test: /\.(js)?bundle$/, | ||
exclude: /index.bundle$/, | ||
}), | ||
], | ||
} | ||
}; | ||
|
||
export default USE_ZEPHYR ? withZephyr()(config) : config; | ||
``` | ||
|
||
Thegrep01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```js title="MiniApp/rspack.config.mjs"{9,19,68} | ||
import path from 'node:path'; | ||
import {fileURLToPath} from 'node:url'; | ||
import * as Repack from '@callstack/repack'; | ||
import {withZephyr} from 'zephyr-repack-plugin'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const USE_ZEPHYR = Boolean(process.env.ZC); | ||
const STANDALONE = Boolean(process.env.STANDALONE); | ||
|
||
/** | ||
* Rspack configuration enhanced with Re.Pack defaults for React Native. | ||
* | ||
* Learn about Rspack configuration: https://rspack.dev/config/ | ||
* Learn about Re.Pack configuration: https://re-pack.dev/docs/guides/configuration | ||
*/ | ||
|
||
const config = env => { | ||
const {platform, mode} = env; | ||
return { | ||
mode, | ||
context: __dirname, | ||
entry: './index.js', | ||
resolve: { | ||
...Repack.getResolveOptions(), | ||
}, | ||
output: { | ||
uniqueName: 'react-native-mini-app', | ||
}, | ||
module: { | ||
rules: [ | ||
...Repack.getJsTransformRules(), | ||
...Repack.getAssetTransformRules({inline: true}), | ||
], | ||
}, | ||
plugins: [ | ||
new Repack.RepackPlugin(), | ||
new Repack.plugins.ModuleFederationPluginV2({ | ||
name: 'MiniApp', | ||
filename: 'MiniApp.container.js.bundle', | ||
dts: false, | ||
exposes: { | ||
'./App': './App.tsx', | ||
}, | ||
shared: { | ||
react: { | ||
singleton: true, | ||
version: '19.0.0', | ||
eager: STANDALONE, | ||
}, | ||
'react-native': { | ||
singleton: true, | ||
version: '0.78.0', | ||
eager: STANDALONE, | ||
}, | ||
}, | ||
}), | ||
new Repack.plugins.HermesBytecodePlugin({ | ||
enabled: mode === 'production', | ||
test: /\.(js)?bundle$/, | ||
exclude: /index.bundle$/, | ||
}), | ||
], | ||
}; | ||
}; | ||
|
||
export default USE_ZEPHYR ? withZephyr()(config) : config; | ||
|
||
``` | ||
|
||
- `ZC` is used to indicate that the bundles are for Zephyr Cloud. | ||
|
||
- Now, when you run or bundle with `ZC=1`, the bundles will be uploaded to Zephyr Cloud. | ||
Thegrep01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
2. Add bundle scripts to the HostApp and MiniApp: | ||
|
||
- In the HostApp and MiniApp, add the following scripts to the package.json files: | ||
|
||
```json title="HostApp/package.json" | ||
"scripts": { | ||
"bundle": "pnpm run bundle:ios && pnpm run bundle:android", | ||
"bundle:ios": "react-native bundle --platform ios --dev false --entry-file index.js", | ||
"bundle:android": "react-native bundle --platform android --dev false --entry-file index.js" | ||
} | ||
``` | ||
|
||
```json title="MiniApp/package.json" | ||
"scripts": { | ||
"bundle": "pnpm run bundle:ios && pnpm run bundle:android", | ||
"bundle:ios": "react-native bundle --platform ios --dev false --entry-file index.js", | ||
"bundle:android": "react-native bundle --platform android --dev false --entry-file index.js" | ||
} | ||
``` | ||
|
||
2. Bundle HostApp and MiniApps, and upload to Zephyr Cloud: | ||
Thegrep01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- Bundle the MiniApp: | ||
|
||
```bash | ||
ZC=1 pnpm --filter MiniApp bundle | ||
``` | ||
|
||
- Bundle the HostApp: | ||
|
||
```bash | ||
ZC=1 pnpm --filter HostApp bundle | ||
``` | ||
|
||
- Command run with `ZC=1` will upload the bundles to Zephyr Cloud. | ||
|
||
|
||
3. Build and run the HostApp in release mode: | ||
|
||
- For Android, you can use the following command from the HostApp android directory: | ||
|
||
```bash | ||
ZC=1 ./gradlew assembleRelease | ||
``` | ||
|
||
{/* TODO: set ZC for iOS */} | ||
{/* - For iOS, you can use the following command: */} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to fix this |
||
|
||
- The HostApp will now load each miniapp bundle from the specified Zephyr Cloud URLs instead of localhost. Verify that the app launches correctly and that each MiniApp is fetched successfully from the remote URL. | ||
Thegrep01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
By following these steps, you can run your HostApp in production mode with the Zephyr, using the remote bundles hosted on Zephyr Cloud. | ||
Thegrep01 marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.