close
logologo
Guide
Config
Plugin
API
Community
Version
Changelog
Rsbuild 0.x Doc
English
简体中文
Guide
Config
Plugin
API
Community
Changelog
Rsbuild 0.x Doc
English
简体中文
logologo
Overview
root
mode
plugins
logLevel
environments

dev

dev.assetPrefix
dev.browserLogs
dev.cliShortcuts
dev.client
dev.hmr
dev.lazyCompilation
dev.liveReload
dev.progressBar
dev.setupMiddlewares
dev.watchFiles
dev.writeToDisk

resolve

resolve.aliasStrategy
resolve.alias
resolve.conditionNames
resolve.dedupe
resolve.extensions
resolve.mainFields

source

source.assetsInclude
source.decorators
source.define
source.entry
source.exclude
source.include
source.preEntry
source.transformImport
source.tsconfigPath

output

output.assetPrefix
output.charset
output.cleanDistPath
output.copy
output.cssModules
output.dataUriLimit
output.distPath
output.emitAssets
output.emitCss
output.externals
output.filenameHash
output.filename
output.injectStyles
output.inlineScripts
output.inlineStyles
output.legalComments
output.manifest
output.minify
output.module
output.overrideBrowserslist
output.polyfill
output.sourceMap
output.target

html

html.appIcon
html.crossorigin
html.favicon
html.inject
html.meta
html.mountId
html.outputStructure
html.scriptLoading
html.tags
html.templateParameters
html.template
html.title

server

server.base
server.compress
server.cors
server.headers
server.historyApiFallback
server.host
server.htmlFallback
server.https
server.middlewareMode
server.open
server.port
server.printUrls
server.proxy
server.publicDir
server.strictPort

security

security.nonce
security.sri

tools

tools.bundlerChain
tools.cssExtract
tools.cssLoader
tools.htmlPlugin
tools.lightningcssLoader
tools.postcss
tools.rspack
tools.styleLoader
tools.swc

performance

performance.buildCache
performance.bundleAnalyze
performance.chunkSplit
performance.dnsPrefetch
performance.preconnect
performance.prefetch
performance.preload
performance.printFileSize
performance.profile
performance.removeConsole
performance.removeMomentLocale

moduleFederation

moduleFederation.options
📝 Edit this page on GitHub
Previous Pageperformance.buildCache
Next Pageperformance.chunkSplit

#performance.bundleAnalyze

  • Type: Object | undefined

Used to enable the webpack-bundle-analyzer plugin to analyze the size of the output.

By default, Rsbuild does not enable webpack-bundle-analyzer. When this feature is enabled, the default configuration is as follows:

const defaultConfig = {
  analyzerMode: 'static',
  openAnalyzer: false,
  // Distinguish by environment names, such as `web`, `node`, etc.
  reportFilename: `report-${environment}.html`,
};

#Enable bundle analyze

You have two ways to enable webpack-bundle-analyzer to analyze the size of the output files.

#Via environment variable

Add the environment variable BUNDLE_ANALYZE=true, for example:

package.json
{
  "scripts": {
    "build:analyze": "BUNDLE_ANALYZE=true rsbuild build"
  }
}

As Windows does not support the above usage, you can also use cross-env to set environment variables. This ensures compatibility across different systems:

package.json
{
  "scripts": {
    "build:analyze": "cross-env BUNDLE_ANALYZE=true rsbuild build"
  },
  "devDependencies": {
    "cross-env": "^7.0.0"
  }
}

#Via configuration

Configure performance.bundleAnalyze to enable it permanently:

rsbuild.config.ts
export default {
  performance: {
    bundleAnalyze: {},
  },
};

#Analysis result

After enabling it, Rsbuild will generate an HTML file that analyzes the size of the output files, and print the following log in the terminal:

Webpack Bundle Analyzer saved report to /Project/my-project/dist/report-web.html

You can manually open the file in the browser and view the detail of the bundle size. When an area is larger, it indicates that its corresponding bundle size is larger.

#Override default configuration

You can override the default configuration through performance.bundleAnalyze, such as enabling the server mode:

rsbuild.config.ts
export default {
  performance: {
    bundleAnalyze: process.env.BUNDLE_ANALYZE
      ? {
          analyzerMode: 'server',
          openAnalyzer: true,
        }
      : {},
  },
};

#Size types

In the webpack-bundle-analyzer panel, you can control size types in the upper left corner (default is Parsed):

  • Stat: The size obtained from the stats object of the bundler, which reflects the size of the code before minification.
  • Parsed: The size of the file on the disk, which reflects the size of the code after minification.
  • Gzipped: The file size requested in the browser reflects the size of the code after minification and gzip.

#Generate stats.json

By setting generateStatsFile to true, stats JSON file will be generated in bundle output directory.

rsbuild.config.ts
export default {
  performance: {
    bundleAnalyze: {
      generateStatsFile: true,
    },
  },
};

In the output directory, you will see stats.json and report-web.html files.

└── dist
    ├── stats.json
    └── report-web.html

If you do not need the report-web.html, you can set analyzerMode to disabled.

rsbuild.config.ts
export default {
  performance: {
    bundleAnalyze: {
      analyzerMode: 'disabled',
      generateStatsFile: true,
    },
  },
};

#Notes

  1. Enabling the server mode will cause the build process to not exit normally.
  2. Enabling bundleAnalyzer will reduce build speed. Therefore, this configuration should not be enabled during daily development, and it is recommended to enable it on demand through the BUNDLE_ANALYZE environment variable.
  3. Since no code minification and other optimizations are performed in the dev phase, the real output size cannot be reflected, so it is recommended to analyze the output size in the build phase.
  4. If the bundleAnalyzer is enabled during the dev phase, to ensure that webpack-bundle-analyzer can access the contents of static assets, Rsbuild will automatically enable the dev.writeToDisk option.