codeSplitting
- Type:
boolean| object with the properties below - Optional
Controls how code splitting is performed.
true: Default behavior, automatic code splitting. (default)false: Inline all dynamic imports into a single bundle (equivalent to deprecatedinlineDynamicImports: true).object: Advanced manual code splitting configuration.
For deeper understanding, please refer to the in-depth documentation.
Example
Basic vendor chunk
export default defineConfig({
output: {
codeSplitting: {
minSize: 20000,
groups: [
{
name: 'vendor',
test: /node_modules/,
},
],
},
},
});Multiple chunk groups with priorities
export default defineConfig({
output: {
codeSplitting: {
groups: [
{
name: 'react-vendor',
test: /node_modules[\\/]react/,
priority: 20,
},
{
name: 'ui-vendor',
test: /node_modules[\\/](antd%7C@mui)/,
priority: 15,
},
{
name: 'vendor',
test: /node_modules/,
priority: 10,
},
{
name: 'common',
minShareCount: 2,
minSize: 10000,
priority: 5,
},
],
},
},
});Size-based splitting
export default defineConfig({
output: {
codeSplitting: {
groups: [
{
name: 'large-libs',
test: /node_modules/,
minSize: 100000, // 100KB
maxSize: 250000, // 250KB
priority: 10,
},
],
},
},
});Default
truegroups?
- Type:
CodeSplittingGroup[] - Optional
Groups to be used for code splitting.
includeDependenciesRecursively?
- Type:
boolean - Optional
By default, each group will also include captured modules' dependencies. This reduces the chance of generating circular chunks.
If you want to disable this behavior, it's recommended to both set
preserveEntrySignatures:false | 'allow-extension'strictExecutionOrder:true
to avoid generating invalid chunks.
Default
truemaxModuleSize?
- Type:
number - Optional
Global fallback of group.maxModuleSize, if it's not specified in the group.
maxSize?
- Type:
number - Optional
Global fallback of group.maxSize, if it's not specified in the group.
minModuleSize?
- Type:
number - Optional
Global fallback of group.minModuleSize, if it's not specified in the group.
minShareCount?
- Type:
number - Optional
Global fallback of group.minShareCount, if it's not specified in the group.
minSize?
- Type:
number - Optional
Global fallback of group.minSize, if it's not specified in the group.