react-native-bundle-discovery 2.0.1 → 2.1.0-rc.2
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 +33 -10
- 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-data.json --format rsdoctor
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
|
|
102
116
|
---
|
|
103
117
|
|
|
104
118
|
### `react-native-bundle-discovery` JS API
|
|
@@ -112,9 +126,18 @@ 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
|
-
### `createProcessModuleFilter(options: ProcessModuleFilterOptions)`
|
|
116
129
|
|
|
117
130
|
|
|
131
|
+
**⚠️ Be cautious sharing reports with `includeCode` enabled**
|
|
132
|
+
|
|
133
|
+
Enabling this option significantly increases report size and **embeds the source code** of your assets.
|
|
134
|
+
|
|
135
|
+
If your code is proprietary 🔒, share these reports responsibly 🤝!
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
### `createResolveRequest(options: ResolveRequestOptions)`
|
|
140
|
+
|
|
118
141
|
| Prop | Default value | Description |
|
|
119
142
|
| ---------------------- | ------------------------- | ----------------------------- |
|
|
120
143
|
| removePromisePolyfill: boolean | `false` | Remove the Promise polyfill as Hermes provide own impl. (issue: [#57702](https://github.com/react/react-native/issues/57702)) |
|
|
@@ -122,20 +145,20 @@ npx react-native-bundle-discovery-ui build metro-stats.json
|
|
|
122
145
|
| removeNewRenderer: boolean | `false` | Whether to remove the new renderer. Set to `true` when New Arch is disabled |
|
|
123
146
|
| removeUTFSequence: boolean | `false` | Remove useless undocumented RN module. |
|
|
124
147
|
|
|
125
|
-
|
|
126
|
-
Simple helper that devs can use to filter out unnecessary modules from the bundle report.
|
|
148
|
+
Helper that creates a custom resolve request function to filter out unnecessary modules from the bundle.
|
|
127
149
|
You can get recommendations during the analysis of the bundle report using the CLI tool.
|
|
128
150
|
|
|
129
151
|
```js
|
|
130
152
|
// metro.config.js
|
|
131
|
-
const {
|
|
153
|
+
const {createResolveRequest} = require('react-native-bundle-discovery');
|
|
154
|
+
const resolveRequest = createResolveRequest({
|
|
155
|
+
removePromisePolyfill: true,
|
|
156
|
+
removeOldRenderer: true,
|
|
157
|
+
removeUTFSequence: true,
|
|
158
|
+
});
|
|
132
159
|
const config = {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
removePromisePolyfill: true,
|
|
136
|
-
removeOldRenderer: true,
|
|
137
|
-
removeUTFSequence: true,
|
|
138
|
-
}),
|
|
160
|
+
resolver: {
|
|
161
|
+
resolveRequest,
|
|
139
162
|
},
|
|
140
163
|
};
|
|
141
164
|
```
|
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