react-native-bundle-discovery 2.0.0-rc.2 → 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.
Files changed (2) hide show
  1. package/README.md +60 -60
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -10,27 +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
- ### 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 :)
13
+ ### Packages:
21
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).
22
19
 
23
20
  ### Setup:
24
21
 
25
22
  There are two ways to install the package:
26
23
 
27
- 1. As in independent tool
28
- 2. Or as a [Rozenite](https://www.rozenite.dev/) plugin (see below).
24
+ 1. As in independent tool (UI + CLI)
25
+ 2. Or as a [Rozenite](_rozenite/README.md) plugin (see: [_rozenite/README.md](_rozenite/README.md))
29
26
 
30
27
  #### 1. Install (independent tool)
31
28
 
32
29
  ```bash
33
- yarn add -D react-native-bundle-discovery react-native-bundle-discovery-ui
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
34
33
  ```
35
34
 
36
35
  Add to your `metro.config.js`:
@@ -49,55 +48,19 @@ const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
49
48
 
50
49
  -const config = {};
51
50
  +const config = {
52
- + serializer: {
53
- + customSerializer: mySerializer
54
- + },
55
- +};
51
+ serializer: { customSerializer: mySerializer },
52
+ };
56
53
 
57
54
  module.exports = mergeConfig(getDefaultConfig(__dirname), config);
58
55
  ```
59
56
 
60
- ---
61
-
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)
57
+ #### 2. Install (as plugin for Rozenite)
95
58
 
59
+ See: [_rozenite/README.md](_rozenite/README.md)
96
60
 
97
61
  ---
98
62
 
99
-
100
- #### 3. Build the app
63
+ ### 3. Build the app
101
64
 
102
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:
103
66
 
@@ -110,28 +73,37 @@ npx react-native bundle \
110
73
  --assets-dest ios/assets
111
74
  ```
112
75
 
113
- #### 4. CLI
76
+ ### 4. Commands
114
77
 
115
- ##### 4.1 View the report in the browser
78
+ #### CLI package
116
79
 
117
- Run webserver to view the report:
80
+ You need to install `react-native-bundle-discovery-cli`
118
81
 
119
82
  ```bash
120
- npx react-native-bundle-discovery-ui server metro-stats.json [--port <port>]
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]
121
88
  ```
122
89
 
123
- ##### 4.2 Build the HTML report
90
+ #### UI package
124
91
 
125
- Run the following command to generate an HTML report from the JSON file:
92
+ You need to install `react-native-bundle-discovery-ui`
126
93
 
127
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
128
99
  npx react-native-bundle-discovery-ui build metro-stats.json
129
100
  ```
130
101
 
131
-
132
102
  ---
133
103
 
134
- ### `createSerializer(options: Options)`
104
+ ### `react-native-bundle-discovery` JS API
105
+
106
+ #### `createSerializer(options: Options)`
135
107
 
136
108
  | Prop | Default value | Description |
137
109
  | ---------------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
@@ -140,6 +112,34 @@ npx react-native-bundle-discovery-ui build metro-stats.json
140
112
  | outputJsonPath: string | `<root>/metro-stats.json` | The path where the JSON report will be saved. Defaults to `metro-stats.json` in project root. |
141
113
  | includeCode: boolean | `true` | Whether to include the source and output code in the JSON report. |
142
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
+
143
143
  ### Financial Contributors
144
144
 
145
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bundle-discovery",
3
- "version": "2.0.0-rc.2",
3
+ "version": "2.0.0-rc.4",
4
4
  "main": "index.js",
5
5
  "repository": "git@github.com:retyui/react-native-bundle-discovery.git",
6
6
  "author": "David <4661784+retyui@users.noreply.github.com>",