react-native-monorepo-config 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@ Helper to configure Metro for a React Native app in a monorepo.
|
|
|
12
12
|
npm install --save-dev react-native-monorepo-config
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
Also make sure that your're using recent version of Node.js, i.e. v20.19.0 and higher (LTS), v22.12.0 and higher (LTS) or v23.4.0 and higher.
|
|
16
|
+
|
|
15
17
|
## Usage
|
|
16
18
|
|
|
17
19
|
Let's consider the following monorepo structure:
|
|
@@ -71,7 +73,43 @@ module.exports = {
|
|
|
71
73
|
|
|
72
74
|
This configuration will setup a few things:
|
|
73
75
|
|
|
74
|
-
- Configure Metro to watch for changes in
|
|
75
|
-
|
|
76
|
+
- Configure Metro to watch for changes in the monorepo root instead of only the current package.
|
|
77
|
+
|
|
78
|
+
This may slow down the bundling process in large monorepos. In that case, you can override `watchFolders` to add specific folders to watch instead:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
module.exports = {
|
|
82
|
+
watchFolders: [
|
|
83
|
+
path.resolve(__dirname),
|
|
84
|
+
// Path to packages that the app depends on
|
|
85
|
+
path.resolve(__dirname, '../packages/a'),
|
|
86
|
+
path.resolve(__dirname, '../packages/b'),
|
|
87
|
+
],
|
|
88
|
+
|
|
89
|
+
...monoRepoConfig,
|
|
90
|
+
};
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- Block packages defined in `peerDependencies` of other packages in the monorepo to avoid duplicate versions from being loaded. They must be added under `dependencies` or `devDependencies` in the app's `package.json`.
|
|
94
|
+
|
|
95
|
+
Loading duplicate versions of some packages such as `react` can cause issues. So this way multiple versions are not loaded. Make sure to specify `peerDependencies` for your packages appropriately.
|
|
96
|
+
|
|
76
97
|
- If the packages defined in `peerDependencies` have been hoisted to the monorepo root, point Metro to them so they can be found.
|
|
77
|
-
- Configure Metro's resolve to prioritize `package.json#source` or the `source` condition in `package.json#exports` so that the app can import source code directly from other packages in the monorepo.
|
|
98
|
+
- Configure Metro's resolve to prioritize `package.json#source` or the `source` condition in `package.json#exports` so that the app can import source code directly from other packages in the monorepo.
|
|
99
|
+
|
|
100
|
+
To utilize this, make sure to add the `source` field to the `package.json` of the packages you want to import from, e.g.:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
"source": "src/index.ts"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Or in the `exports` field if you're using `exports` field and Metro 0.82.0+:
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
"exports": {
|
|
110
|
+
".": {
|
|
111
|
+
"source": "./src/index.ts",
|
|
112
|
+
// other conditions...
|
|
113
|
+
},
|
|
114
|
+
}
|
|
115
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-monorepo-config",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Configure Metro for a React Native app in a monorepo",
|
|
5
5
|
"repository": "https://github.com/satya164/react-native-monorepo-config",
|
|
6
6
|
"author": "Satyajit Sahoo <satyajit.happy@gmail.com> (https://github.com/satya164/)",
|