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.bundleAnalyze
Next Pageperformance.dnsPrefetch

#performance.chunkSplit

  • Type: ChunkSplit
  • Default: { strategy: 'split-by-experience' }

performance.chunkSplit configures the chunk splitting strategy. The type definition for ChunkSplit:

TIP

See the Code Splitting guide for detailed usage.

#chunkSplit.strategy

Rsbuild supports the following chunk splitting strategies:

  • split-by-experience: an empirical splitting strategy, automatically splits some commonly used npm packages into chunks of moderate size.
  • split-by-module: split by npm package granularity, each npm package corresponds to a chunk.
  • split-by-size: automatically split according to module size.
  • all-in-one: bundle all codes into one chunk.
  • single-vendor: bundle all npm packages into a single chunk.
  • custom: custom chunk splitting strategy.

#Type definition

The complete type definition for performance.chunkSplit:

type ForceSplitting = RegExp[] | Record<string, RegExp>;

interface BaseChunkSplit {
  strategy?:
    | 'split-by-module'
    | 'split-by-experience'
    | 'all-in-one'
    | 'single-vendor';
  override?: Rspack.OptimizationSplitChunksOptions;
  forceSplitting?: ForceSplitting;
}

interface SplitBySize extends BaseSplitRules {
  strategy: 'split-by-size';
  minSize?: number;
  maxSize?: number;
}

interface SplitCustom extends BaseSplitRules {
  strategy: 'custom';
  splitChunks?: SplitChunks;
}

type ChunkSplit = BaseChunkSplit | SplitBySize | SplitCustom;

#Default strategy

By default, Rsbuild uses the split-by-experience strategy. To use other chunk splitting strategies, specify them through the strategy option, for example:

export default {
  performance: {
    chunkSplit: {
      strategy: 'all-in-one',
    },
  },
};

#chunkSplit.minSize

  • Type: number
  • Default: 10000

When chunkSplit.strategy is split-by-size, you can specify the minimum size of a chunk via chunkSplit.minSize, the unit is bytes. The default value is 10000. For example:

export default {
  performance: {
    chunkSplit: {
      strategy: 'split-by-size',
      minSize: 20000,
    },
  },
};

#chunkSplit.maxSize

  • Type: number
  • Default: Number.POSITIVE_INFINITY

When chunkSplit.strategy is split-by-size, you can specify the maximum size of a chunk via chunkSplit.maxSize, the unit is bytes. The default value is Number.POSITIVE_INFINITY. For example:

export default {
  performance: {
    chunkSplit: {
      strategy: 'split-by-size',
      maxSize: 50000,
    },
  },
};

#chunkSplit.forceSplitting

  • Type: RegExp[] | Record<string, RegExp>
  • Default: []

Via chunkSplit.forceSplitting, you can specify the npm packages that need to be forced to split.

For example, split the axios library under node_modules into axios.js:

export default {
  performance: {
    chunkSplit: {
      forceSplitting: {
        axios: /node_modules[\\/]axios/,
      },
    },
  },
};

This is an easier way than configuring Rspack's splitChunks directly.

TIP

Chunks split using the forceSplitting configuration will be inserted into the HTML file as resources requested for the initial screen using <script> tags. Therefore, please split them appropriately based on the actual scenario to avoid excessive size of initial screen resources.

#chunkSplit.splitChunks

When chunkSplit.strategy is custom, you can specify the custom Rspack chunk splitting config via chunkSplit.splitChunks. This config will be merged with the Rspack splitChunks config (the cacheGroups config will also be merged). For example:

export default {
  performance: {
    chunkSplit: {
      strategy: 'custom',
      splitChunks: {
        cacheGroups: {
          react: {
            test: /node_modules[\\/](react|react-dom)[\\/]/,
            name: 'react',
            chunks: 'all',
          },
        },
      },
    },
  },
};

#chunkSplit.override

When chunkSplit.strategy is split-by-experience, split-by-module, split-by-size or single-vendor, you can specify the custom Rspack chunk splitting config via chunkSplit.override. This config will be merged with the Rspack splitChunks config (the cacheGroups config will also be merged). For example:

export default {
  performance: {
    chunkSplit: {
      override: {
        cacheGroups: {
          react: {
            test: /node_modules[\\/](react|react-dom)[\\/]/,
            name: 'react',
            chunks: 'all',
          },
        },
      },
    },
  },
};

#Targets

performance.chunkSplit only works when output.target is web. This means that when output.target is node or web-worker, performance.chunkSplit will not take effect.

Typically, Node bundles do not need to be split to optimize loading performance, if you need to split Node bundles, you can use the tools.rspack configuration to configure Rspack's optimization.splitChunks option:

export default {
  tools: {
    rspack: {
      optimization: {
        splitChunks: {
          // options
        },
      },
    },
  },
};