react-native-bundle-discovery 2.0.0-rc.1 → 2.0.0-rc.3
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 +2 -44
- package/index.js +47 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,22 +10,13 @@ With this tool, you can easily explore your app's codebase, identify large or he
|
|
|
10
10
|
<img width="800" alt="" src="./assets/img.png" />
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
### What you should consider when analyzing your bundle
|
|
14
|
-
|
|
15
|
-
1. if you use **React 19** then it's time to remove a `prop-types` package from your bundle.
|
|
16
|
-
2. Search for `development|debug|dev|storybook` modules in your production JS bundle (it's a dead code that should not be there).
|
|
17
|
-
3. Also check polyfills duplicates (search example: `url|fetch|crypto|buffer|base-?64`).
|
|
18
|
-
4. Verify that you don't have any similar packages in your bundle (search example: `object|just-|debounce|ramda|lodash|underscore`). I often see that devs use both `lodash/debounce`, `lodash.debounce` and `debounce` in their projects. Or mix `ramda`, `underscore` and `lodash`._
|
|
19
|
-
5. Try to find `package.json$` files in your bundle. They are often used to get only the package `version/name` but all other fields are not needed in the bundle.
|
|
20
|
-
6. Please provide your ideas soo other devs can benefit from them :)
|
|
21
|
-
|
|
22
13
|
|
|
23
14
|
### Setup:
|
|
24
15
|
|
|
25
16
|
There are two ways to install the package:
|
|
26
17
|
|
|
27
|
-
1. As in independent tool
|
|
28
|
-
2. Or as a [Rozenite](https://www.rozenite.dev/) plugin
|
|
18
|
+
1. As in independent tool (UI + CLI)
|
|
19
|
+
2. Or as a [Rozenite](https://www.rozenite.dev/) plugin
|
|
29
20
|
|
|
30
21
|
#### 1. Install (independent tool)
|
|
31
22
|
|
|
@@ -59,39 +50,6 @@ module.exports = mergeConfig(getDefaultConfig(__dirname), config);
|
|
|
59
50
|
|
|
60
51
|
---
|
|
61
52
|
|
|
62
|
-
#### 2. Install as a Rozenite plugin (OPTIONAL)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
yarn dlx rozenite@latest init # init rozenite in your project (from: https://www.rozenite.dev/docs/getting-started)
|
|
67
|
-
yarn add -D react-native-bundle-discovery-rozenite-plugin # add the plugin to your project
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Then in the `metro.config.js` file add the following:
|
|
71
|
-
|
|
72
|
-
```diff
|
|
73
|
-
const { withRozenite } = require('@rozenite/metro');
|
|
74
|
-
+const { withRozeniteBundleDiscoveryPlugin } = require('react-native-bundle-discovery-rozenite-plugin');
|
|
75
|
-
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Metro configuration
|
|
79
|
-
* https://reactnative.dev/docs/metro
|
|
80
|
-
*
|
|
81
|
-
* @type {import('@react-native/metro-config').MetroConfig}
|
|
82
|
-
*/
|
|
83
|
-
const config = {};
|
|
84
|
-
|
|
85
|
-
module.exports = withRozenite(
|
|
86
|
-
mergeConfig(getDefaultConfig(__dirname), config),
|
|
87
|
-
{
|
|
88
|
-
+ enhanceMetroConfig: config => withRozeniteBundleDiscoveryPlugin(config, { /* Your Bundle Discovery Options */ }),
|
|
89
|
-
enabled: true,
|
|
90
|
-
},
|
|
91
|
-
);
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Now you can run `yarn start` and open [React Native DevTools](https://reactnative.dev/docs/react-native-devtools)
|
|
95
53
|
|
|
96
54
|
|
|
97
55
|
---
|
package/index.js
CHANGED
|
@@ -115,8 +115,12 @@ function createJsonReport({
|
|
|
115
115
|
outputJsonPath,
|
|
116
116
|
rootFolder,
|
|
117
117
|
silent,
|
|
118
|
+
options,
|
|
118
119
|
}) {
|
|
119
|
-
const
|
|
120
|
+
const { processModuleFilter = () => true } = options || {};
|
|
121
|
+
const dependencies = Array.from(graph.dependencies.values()).filter(
|
|
122
|
+
processModuleFilter,
|
|
123
|
+
);
|
|
120
124
|
|
|
121
125
|
const stats = {
|
|
122
126
|
date: Date.now(),
|
|
@@ -184,6 +188,7 @@ function createSerializer({
|
|
|
184
188
|
outputJsonPath: myOutputJsonPath,
|
|
185
189
|
rootFolder: projectRoot,
|
|
186
190
|
silent,
|
|
191
|
+
options,
|
|
187
192
|
});
|
|
188
193
|
|
|
189
194
|
return code;
|
|
@@ -192,4 +197,44 @@ function createSerializer({
|
|
|
192
197
|
return customSerializer;
|
|
193
198
|
}
|
|
194
199
|
|
|
195
|
-
|
|
200
|
+
const createProcessModuleFilter =
|
|
201
|
+
({
|
|
202
|
+
removePromisePolyfill = false, // Remove useless polyfill (Hermes already has Promise)
|
|
203
|
+
removeOldRenderer = false, // Should be true when new ARCH is enabled
|
|
204
|
+
removeNewRenderer = false, // Should be true when new ARCH is disabled
|
|
205
|
+
removeUTFSequence = false, // Remove useless code
|
|
206
|
+
} = {}) =>
|
|
207
|
+
(module) => {
|
|
208
|
+
if (
|
|
209
|
+
removePromisePolyfill &&
|
|
210
|
+
module.path.endsWith("/react-native/Libraries/Promise.js")
|
|
211
|
+
) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
if (
|
|
215
|
+
removeOldRenderer &&
|
|
216
|
+
module.path.endsWith(
|
|
217
|
+
"/react-native/Libraries/Renderer/shims/ReactNative.js",
|
|
218
|
+
)
|
|
219
|
+
) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
if (
|
|
223
|
+
removeNewRenderer &&
|
|
224
|
+
module.path.endsWith(
|
|
225
|
+
"/react-native/Libraries/Renderer/shims/ReactFabric.js",
|
|
226
|
+
)
|
|
227
|
+
) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
if (
|
|
231
|
+
removeUTFSequence &&
|
|
232
|
+
module.path.endsWith("/react-native/Libraries/UTFSequence.js")
|
|
233
|
+
) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return true;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
module.exports = { createSerializer, createProcessModuleFilter };
|
package/package.json
CHANGED