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.
WARNING
Be aware that manual code splitting can change the behavior of the application if side effects are triggered before the corresponding modules are actually used. You can change the chunking configuration to keep order-sensitive modules together, or you can use the output.strictExecutionOrder option to preserve source execution order. The option wraps modules so their bodies run in source order, at a bundle-size cost; experimental.onDemandWrapping replaces wrap-all with a conservative plan derived from predicted chunk execution hazards.
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/,
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
Global fallback of group.includeDependenciesRecursively, if it's not specified in the group.
maxModuleSize?
- 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.