-
Notifications
You must be signed in to change notification settings - Fork 14
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
18
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 all commits
Commits
Show all changes
18 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 b68c019
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
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -76,7 +76,226 @@ On the downside, this approach increased coupling, which resulted in challenges | |||||||||||
|
||||||||||||
There is also a third solution: using a single NavigationContainer in the host application while exposing navigators from the mini applications. This approach reduces coupling, allowing mini applications to maintain control over their navigators. However, it can lead to undesirable navigation structures, such as deeply nested stack navigators, and a complex linking setup that requires synchronization between the host and mini applications. | ||||||||||||
|
||||||||||||
|
||||||||||||
## Running the application in release mode with Zephyr | ||||||||||||
|
||||||||||||
When you are using Zephyr with Re.Pack, the HostApp auto-loads MiniApps' bundles from Zephyr. To run the app in production/release mode with Zephyr, the process involves configuring your Zephyr environment - and `zephyr-repack-plugin` will auto-retrieving the latest deployed remote URLs as well as updating the HostApp’s module federation configuration during the bundling. 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. | ||||||||||||
|
||||||||||||
We will soon launch `react-native-zephyr-sdk` to auto-rollback, roll-forward MiniApps during runtime. To use `react-native-zephyr-sdk`, you must use `zephyr-repack-plugin` during build time. | ||||||||||||
|
||||||||||||
|
||||||||||||
### 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: | ||||||||||||
|
||||||||||||
#### HostApp's configuration | ||||||||||||
|
||||||||||||
```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; | ||||||||||||
``` | ||||||||||||
|
||||||||||||
#### MiniApp's configuration | ||||||||||||
|
||||||||||||
```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 deployed to Zephyr Cloud. | ||||||||||||
|
||||||||||||
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 deploy to Zephyr Cloud: | ||||||||||||
|
||||||||||||
- Bundle the MiniApp: | ||||||||||||
|
||||||||||||
```bash | ||||||||||||
ZC=1 pnpm --filter MiniApp bundle | ||||||||||||
``` | ||||||||||||
|
||||||||||||
- Bundle the HostApp: | ||||||||||||
|
||||||||||||
```bash | ||||||||||||
ZC=1 pnpm --filter HostApp bundle | ||||||||||||
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.
Suggested change
|
||||||||||||
``` | ||||||||||||
|
||||||||||||
- Command run with `ZC=1` will upload the bundles to Zephyr Cloud. | ||||||||||||
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.
Suggested change
|
||||||||||||
|
||||||||||||
|
||||||||||||
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: */} | ||||||||||||
|
||||||||||||
- The HostApp will now load each MiniApp's 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. | ||||||||||||
|
||||||||||||
By following these steps, you can run your HostApp in production mode with Zephyr, using the remote bundles (MiniApps) deployed on Zephyr Cloud. | ||||||||||||
|
||||||||||||
|
||||||||||||
|
||||||||||||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to help us isolate platform deploy