react-native-bundle-discovery 2.0.0 → 2.1.0-rc.1
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 +24 -11
- package/index.js +69 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,6 +99,20 @@ npx react-native-bundle-discovery-ui metro-stats.json [--port <port>]
|
|
|
99
99
|
npx react-native-bundle-discovery-ui build metro-stats.json
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
### Re.Pack Support
|
|
106
|
+
|
|
107
|
+
If you've migrated to [Re.Pack](https://re-pack.dev/docs/guides/bundle-analysis), you can still use this package to analyze bundles generated by Re.Pack.
|
|
108
|
+
|
|
109
|
+
Learn more: [Rsdoctor.md](./Rsdoctor.md)
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npx react-native-bundle-discovery-ui rsdoctor-report.json --format rsdoctor
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
|
|
102
116
|
---
|
|
103
117
|
|
|
104
118
|
### `react-native-bundle-discovery` JS API
|
|
@@ -112,8 +126,7 @@ npx react-native-bundle-discovery-ui build metro-stats.json
|
|
|
112
126
|
| outputJsonPath: string | `<root>/metro-stats.json` | The path where the JSON report will be saved. Defaults to `metro-stats.json` in project root. |
|
|
113
127
|
| includeCode: boolean | `true` | Whether to include the source and output code in the JSON report. |
|
|
114
128
|
|
|
115
|
-
### `
|
|
116
|
-
|
|
129
|
+
### `createResolveRequest(options: ResolveRequestOptions)`
|
|
117
130
|
|
|
118
131
|
| Prop | Default value | Description |
|
|
119
132
|
| ---------------------- | ------------------------- | ----------------------------- |
|
|
@@ -122,20 +135,20 @@ npx react-native-bundle-discovery-ui build metro-stats.json
|
|
|
122
135
|
| removeNewRenderer: boolean | `false` | Whether to remove the new renderer. Set to `true` when New Arch is disabled |
|
|
123
136
|
| removeUTFSequence: boolean | `false` | Remove useless undocumented RN module. |
|
|
124
137
|
|
|
125
|
-
|
|
126
|
-
Simple helper that devs can use to filter out unnecessary modules from the bundle report.
|
|
138
|
+
Helper that creates a custom resolve request function to filter out unnecessary modules from the bundle.
|
|
127
139
|
You can get recommendations during the analysis of the bundle report using the CLI tool.
|
|
128
140
|
|
|
129
141
|
```js
|
|
130
142
|
// metro.config.js
|
|
131
|
-
const {
|
|
143
|
+
const {createResolveRequest} = require('react-native-bundle-discovery');
|
|
144
|
+
const resolveRequest = createResolveRequest({
|
|
145
|
+
removePromisePolyfill: true,
|
|
146
|
+
removeOldRenderer: true,
|
|
147
|
+
removeUTFSequence: true,
|
|
148
|
+
});
|
|
132
149
|
const config = {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
removePromisePolyfill: true,
|
|
136
|
-
removeOldRenderer: true,
|
|
137
|
-
removeUTFSequence: true,
|
|
138
|
-
}),
|
|
150
|
+
resolver: {
|
|
151
|
+
resolveRequest,
|
|
139
152
|
},
|
|
140
153
|
};
|
|
141
154
|
```
|
package/index.js
CHANGED
|
@@ -197,6 +197,70 @@ function createSerializer({
|
|
|
197
197
|
return customSerializer;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Usage:
|
|
202
|
+
*
|
|
203
|
+
* ```js
|
|
204
|
+
* // metro.config.js
|
|
205
|
+
* const { createResolveRequest } = require("react-native-bundle-discovery");
|
|
206
|
+
* const resolveRequest = createResolveRequest({
|
|
207
|
+
* removePromisePolyfill: true,
|
|
208
|
+
* });
|
|
209
|
+
* const config = {
|
|
210
|
+
* resolver: {
|
|
211
|
+
* resolveRequest,
|
|
212
|
+
* },
|
|
213
|
+
* };
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
const empty = { type: "empty" };
|
|
217
|
+
const createResolveRequest = ({
|
|
218
|
+
removePromisePolyfill = false, // Remove useless polyfill (Hermes already has Promise)
|
|
219
|
+
removeOldRenderer = false, // Should be true when new ARCH is enabled
|
|
220
|
+
removeNewRenderer = false, // Should be true when new ARCH is disabled
|
|
221
|
+
removeUTFSequence = false, // Remove useless code
|
|
222
|
+
} = {}) => {
|
|
223
|
+
const resolveRequest = (context, ...rest) => {
|
|
224
|
+
const result = context.resolveRequest(context, ...rest);
|
|
225
|
+
if (context.dev) {
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
if (
|
|
229
|
+
removeUTFSequence &&
|
|
230
|
+
result?.filePath?.endsWith("/react-native/Libraries/UTFSequence.js")
|
|
231
|
+
) {
|
|
232
|
+
return empty;
|
|
233
|
+
}
|
|
234
|
+
if (
|
|
235
|
+
removePromisePolyfill &&
|
|
236
|
+
result?.filePath?.endsWith("/react-native/Libraries/Promise.js")
|
|
237
|
+
) {
|
|
238
|
+
return empty;
|
|
239
|
+
}
|
|
240
|
+
if (
|
|
241
|
+
removeOldRenderer &&
|
|
242
|
+
result?.filePath?.endsWith(
|
|
243
|
+
"/react-native/Libraries/Renderer/shims/ReactNative.js",
|
|
244
|
+
)
|
|
245
|
+
) {
|
|
246
|
+
return empty;
|
|
247
|
+
}
|
|
248
|
+
if (
|
|
249
|
+
removeNewRenderer &&
|
|
250
|
+
result?.filePath?.endsWith(
|
|
251
|
+
"/react-native/Libraries/Renderer/shims/ReactFabric.js",
|
|
252
|
+
)
|
|
253
|
+
) {
|
|
254
|
+
return empty;
|
|
255
|
+
}
|
|
256
|
+
return result;
|
|
257
|
+
};
|
|
258
|
+
return resolveRequest;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* @deprecated Use `createResolveRequest` instead.
|
|
263
|
+
*/
|
|
200
264
|
const createProcessModuleFilter =
|
|
201
265
|
({
|
|
202
266
|
removePromisePolyfill = false, // Remove useless polyfill (Hermes already has Promise)
|
|
@@ -237,4 +301,8 @@ const createProcessModuleFilter =
|
|
|
237
301
|
return true;
|
|
238
302
|
};
|
|
239
303
|
|
|
240
|
-
module.exports = {
|
|
304
|
+
module.exports = {
|
|
305
|
+
createResolveRequest,
|
|
306
|
+
createSerializer,
|
|
307
|
+
createProcessModuleFilter,
|
|
308
|
+
};
|
package/package.json
CHANGED