react-native-bundle-discovery 2.0.0-rc.3 → 2.0.0-rc.4
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 +60 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,18 +10,26 @@ 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
|
+
### Packages:
|
|
14
|
+
|
|
15
|
+
- `react-native-bundle-discovery` - simple JS library to generate a JSON report of the bundle.
|
|
16
|
+
- `react-native-bundle-discovery-ui` - UI to visualize the bundle report.
|
|
17
|
+
- `react-native-bundle-discovery-cli` - CLI to analyze the bundle report.
|
|
18
|
+
- `react-native-bundle-discovery-rozenite-plugin` - Rozenite plugin to integrate UI tool to [React Native DevTools](https://reactnative.dev/docs/react-native-devtools).
|
|
13
19
|
|
|
14
20
|
### Setup:
|
|
15
21
|
|
|
16
22
|
There are two ways to install the package:
|
|
17
23
|
|
|
18
24
|
1. As in independent tool (UI + CLI)
|
|
19
|
-
2. Or as a [Rozenite](
|
|
25
|
+
2. Or as a [Rozenite](_rozenite/README.md) plugin (see: [_rozenite/README.md](_rozenite/README.md))
|
|
20
26
|
|
|
21
27
|
#### 1. Install (independent tool)
|
|
22
28
|
|
|
23
29
|
```bash
|
|
24
|
-
yarn add -D react-native-bundle-discovery
|
|
30
|
+
yarn add -D react-native-bundle-discovery # required for generating the JSON report
|
|
31
|
+
yarn add -D react-native-bundle-discovery-ui # optional: used for visualizing the report in the browser
|
|
32
|
+
yarn add -D react-native-bundle-discovery-cli # optional: used for analysis of the report in the CLI
|
|
25
33
|
```
|
|
26
34
|
|
|
27
35
|
Add to your `metro.config.js`:
|
|
@@ -40,22 +48,19 @@ const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
|
|
|
40
48
|
|
|
41
49
|
-const config = {};
|
|
42
50
|
+const config = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
+ },
|
|
46
|
-
+};
|
|
51
|
+
serializer: { customSerializer: mySerializer },
|
|
52
|
+
};
|
|
47
53
|
|
|
48
54
|
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
|
|
49
55
|
```
|
|
50
56
|
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
#### 2. Install (as plugin for Rozenite)
|
|
53
58
|
|
|
59
|
+
See: [_rozenite/README.md](_rozenite/README.md)
|
|
54
60
|
|
|
55
61
|
---
|
|
56
62
|
|
|
57
|
-
|
|
58
|
-
#### 3. Build the app
|
|
63
|
+
### 3. Build the app
|
|
59
64
|
|
|
60
65
|
As example, for iOS you can run the following command, and it will generate the `metro-stats.json` file in the root of your project:
|
|
61
66
|
|
|
@@ -68,28 +73,37 @@ npx react-native bundle \
|
|
|
68
73
|
--assets-dest ios/assets
|
|
69
74
|
```
|
|
70
75
|
|
|
71
|
-
|
|
76
|
+
### 4. Commands
|
|
72
77
|
|
|
73
|
-
|
|
78
|
+
#### CLI package
|
|
74
79
|
|
|
75
|
-
|
|
80
|
+
You need to install `react-native-bundle-discovery-cli`
|
|
76
81
|
|
|
77
82
|
```bash
|
|
78
|
-
|
|
83
|
+
# Display all recommended optimizations for the bundle
|
|
84
|
+
npx react-native-bundle-discovery-cli metro-stats.json
|
|
85
|
+
|
|
86
|
+
# Display all packages in the bundle report
|
|
87
|
+
npx react-native-bundle-discovery-cli packages metro-stats.json [--sort size|name] [--format json|table|default]
|
|
79
88
|
```
|
|
80
89
|
|
|
81
|
-
|
|
90
|
+
#### UI package
|
|
82
91
|
|
|
83
|
-
|
|
92
|
+
You need to install `react-native-bundle-discovery-ui`
|
|
84
93
|
|
|
85
94
|
```bash
|
|
95
|
+
# Start server to view the report in the browser (default port: 8079)
|
|
96
|
+
npx react-native-bundle-discovery-ui metro-stats.json [--port <port>]
|
|
97
|
+
|
|
98
|
+
# Build the report into a static HTML file
|
|
86
99
|
npx react-native-bundle-discovery-ui build metro-stats.json
|
|
87
100
|
```
|
|
88
101
|
|
|
89
|
-
|
|
90
102
|
---
|
|
91
103
|
|
|
92
|
-
### `
|
|
104
|
+
### `react-native-bundle-discovery` JS API
|
|
105
|
+
|
|
106
|
+
#### `createSerializer(options: Options)`
|
|
93
107
|
|
|
94
108
|
| Prop | Default value | Description |
|
|
95
109
|
| ---------------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -98,6 +112,34 @@ npx react-native-bundle-discovery-ui build metro-stats.json
|
|
|
98
112
|
| outputJsonPath: string | `<root>/metro-stats.json` | The path where the JSON report will be saved. Defaults to `metro-stats.json` in project root. |
|
|
99
113
|
| includeCode: boolean | `true` | Whether to include the source and output code in the JSON report. |
|
|
100
114
|
|
|
115
|
+
### `createProcessModuleFilter(options: ProcessModuleFilterOptions)`
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
| Prop | Default value | Description |
|
|
119
|
+
| ---------------------- | ------------------------- | ----------------------------- |
|
|
120
|
+
| removePromisePolyfill: boolean | `false` | Remove the Promise polyfill as Hermes provide own impl. (issue: [#57702](https://github.com/react/react-native/issues/57702)) |
|
|
121
|
+
| removeOldRenderer: boolean | `false` | Whether to remove the old renderer. Set to `true` when New Arch is enabled |
|
|
122
|
+
| removeNewRenderer: boolean | `false` | Whether to remove the new renderer. Set to `true` when New Arch is disabled |
|
|
123
|
+
| removeUTFSequence: boolean | `false` | Remove useless undocumented RN module. |
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
Simple helper that devs can use to filter out unnecessary modules from the bundle report.
|
|
127
|
+
You can get recommendations during the analysis of the bundle report using the CLI tool.
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
// metro.config.js
|
|
131
|
+
const {createProcessModuleFilter} = require('react-native-bundle-discovery');
|
|
132
|
+
const config = {
|
|
133
|
+
serializer: {
|
|
134
|
+
processModuleFilter: createProcessModuleFilter({
|
|
135
|
+
removePromisePolyfill: true,
|
|
136
|
+
removeOldRenderer: true,
|
|
137
|
+
removeUTFSequence: true,
|
|
138
|
+
}),
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
```
|
|
142
|
+
|
|
101
143
|
### Financial Contributors
|
|
102
144
|
|
|
103
145
|
Become a financial contributor at [OpenCollective](https://opencollective.com/react-native-bundle-discovery) or [GitHub Sponsors](https://github.com/sponsors/retyui)
|
package/package.json
CHANGED