Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simple tooling to explore bundle size 📦, spot heavy packages, and inspect module/code structure in React Native apps.

NotificationsYou must be signed in to change notification settings

retyui/react-native-bundle-discovery

Repository files navigation

A simple package that helps developers visualize and analyze the bundle size of React Native apps.With this tool, you can easily explore your app's codebase, identify large or heavy packages, and inspect the structure of modules and code within your project.

What you should consider when analyzing your bundle

  1. if you useReact 19 then it's time to remove aprop-types package from your bundle.
  2. Search fordevelopment|debug|dev|storybook modules in your production JS bundle (it's a dead code that should not be there).
  3. Also check polyfills duplicates (search example:url|fetch|crypto|buffer|base-?64).
  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 bothlodash/debounce,lodash.debounce anddebounce in their projects. Or mixramda,underscore andlodash._
  5. Try to findpackage.json$ files in your bundle. They are often used to get only the packageversion/name but all other fields are not needed in the bundle.
  6. Please provide your ideas soo other devs can benefit from them :)

Setup:

There are two ways to install the package:

  1. As in independent tool
  2. Or as aRozenite plugin (see below).

1. Install (independent tool)

yarn add -D react-native-bundle-discovery

Add to yourmetro.config.js:

// metro.config.jsconst {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');+const {createSerializer} = require('react-native-bundle-discovery');+const mySerializer = createSerializer({+  includeCode: true, // Useful if you want to compare source/bundle code (but a report file will be larger)+  projectRoot: __dirname,+   //^^^ ⚠️ WARNING: In a monorepo setup, this should point to the monorepo root,+   //                not the individual package directory.+});-const config = {};+const config = {+  serializer: {+    customSerializer: mySerializer+  },+};module.exports = mergeConfig(getDefaultConfig(__dirname), config);

2. Install as a Rozenite plugin (OPTIONAL)

yarn dlx rozenite@latest init# init rozenite in your project (from: https://www.rozenite.dev/docs/getting-started)yarn add -D react-native-bundle-discovery-rozenite-plugin# add the plugin to your project

Then in themetro.config.js file add the following:

const { withRozenite } = require('@rozenite/metro');+const { withRozeniteBundleDiscoveryPlugin } = require('react-native-bundle-discovery-rozenite-plugin');const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');/** * Metro configuration * https://reactnative.dev/docs/metro * * @type {import('@react-native/metro-config').MetroConfig} */const config = {};module.exports = withRozenite(  mergeConfig(getDefaultConfig(__dirname), config),  {+    enhanceMetroConfig: config => withRozeniteBundleDiscoveryPlugin(config, { /* Your Bundle Discovery Options */ }),    enabled: true,  },);

Now you can runyarn start and openReact Native DevTools


3. Build the app

As example, for iOS you can run the following command, and it will generate themetro-stats.json file in the root of your project:

npx react-native bundle \  --entry-file index.js \  --platform ios \  --devfalse \  --bundle-output ios/main.jsbundle \  --assets-dest ios/assets

4. CLI

4.1 View the report in the browser

Run webserver to view the report:

npx react-native-bundle-discovery server metro-stats.json [--port<port>]
4.2 Build the HTML report

Run the following command to generate an HTML report from the JSON file:

npx react-native-bundle-discovery build metro-stats.json

createSerializer(optiosn: Options)

PropDefault valueDescription
serializer: FunctionDefault serializerA custom serializer function. If not provided, a default serializer is used.
projectRoot: stringRequiredThe root directory of the project.⚠️ In a monorepo setup, this should point to the monorepo root, not the individual package directory.
outputJsonPath: string<root>/metro-stats.jsonThe path where the JSON report will be saved. Defaults tometro-stats.json in project root.
includeCode: booleantrueWhether to include the source and output code in the JSON report.

Financial Contributors

Become a financial contributor atOpenCollective orGitHub Sponsors

Other

Similar projects:

Built usingDiscovery.js:

About

Simple tooling to explore bundle size 📦, spot heavy packages, and inspect module/code structure in React Native apps.

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

 

[8]ページ先頭

©2009-2025 Movatter.jp