> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Bundle analysis

Bundle analysis is a crucial process that helps you understand your app's performance bottlenecks and identify opportunities for optimization. By analyzing your bundle, you can gain insights into bundle size and composition, module dependencies, duplicate modules, and compilation time. We recommend using [Rsdoctor](https://rsdoctor.rs/) for bundle analysis, though you can also check our [alternative tools section](#alternative-tools) for other options.

## Rsdoctor

**Rsdoctor** provides comprehensive visualization of the build process, offering detailed insights into compilation time, compilation transformations, module dependencies, duplicate modules, and bundle size analysis.

### Installation


**Rspack**


```sh [npm]
npm install @rsdoctor/rspack-plugin -D
```

```sh [yarn]
yarn add @rsdoctor/rspack-plugin -D
```

```sh [pnpm]
pnpm add @rsdoctor/rspack-plugin -D
```

```sh [bun]
bun add @rsdoctor/rspack-plugin -D
```


**webpack**


```sh [npm]
npm install @rsdoctor/webpack-plugin -D
```

```sh [yarn]
yarn add @rsdoctor/webpack-plugin -D
```

```sh [pnpm]
pnpm add @rsdoctor/webpack-plugin -D
```

```sh [bun]
bun add @rsdoctor/webpack-plugin -D
```


### Usage

:::danger Only for development
Please do not use Rsdoctor in production version.

The `process.env.RSDOCTOR` is used to conditionally enable the plugin just for the development environment.
:::

Initialize the plugin in your bundler configuration:


**Rspack**

```ts title=rspack.config.mjs
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';

export default {
  // ...
  plugins: [
    process.env.RSDOCTOR &&
      new RsdoctorRspackPlugin({
        // plugin options
      }),
  ],
};
```


**webpack**

```ts title=webpack.config.js
import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin';

export default {
  // ...
  plugins: [
    process.env.RSDOCTOR &&
      new RsdoctorWebpackPlugin({
        // plugin options
      }),
  ],
};
```


Use the `RSDOCTOR` environment variable when running the build:

```bash
RSDOCTOR=true npx react-native bundle
```

:::tip Specific platform analysis
For better analysis results, it's recommended to run a single platform build using the `--platform` option:

```bash
RSDOCTOR=true npx react-native bundle --platform <platform>
```

This helps to get more focused and accurate bundle analysis for each platform.
:::

After running the above commands, when the build is completed, it will open the build analysis page. For complete features, please refer to [Rsdoctor documentation](https://rsdoctor.rs/).

### Options

The `RsdoctorRspackPlugin` / `RsdoctorWebpackPlugin` plugins provide several options to customize the build analysis. Read more about it [here](https://rsdoctor.rs/config/options/options).

## Alternative tools

- [Sonda](https://github.com/filipsobol/sonda) - Universal visualizer and analyzer for JavaScript and CSS. Compatible with Re.Pack.
- [Webpack Bundle Analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) - A tool for analyzing the bundle size of your React Native application.
- [react-native-bundle-discovery](https://retyui.github.io/bundle-discovery/docs/guides/repack) - Simple tooling to inspect the JS bundle internals.
- [source-map-explorer](https://github.com/danvk/source-map-explorer) - A tool for analyzing the bundle size of your React Native application.
