Skip to content

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 deprecated inlineDynamicImports: 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 group some modules so that the modules are reordered, or you can use the output.strictExecutionOrder option to ensure that modules are executed in the order they are imported with the cost of a slight increase in bundle size.

Example

Basic vendor chunk

js
export default defineConfig({
  output: {
    codeSplitting: {
      minSize: 20000,
      groups: [
        {
          name: 'vendor',
          test: /node_modules/,
        },
      ],
    },
  },
});

Multiple chunk groups with priorities

js
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

js
export default defineConfig({
  output: {
    codeSplitting: {
      groups: [
        {
          name: 'large-libs',
          test: /node_modules/,
          minSize: 100000, // 100KB
          maxSize: 250000, // 250KB
          priority: 10,
        },
      ],
    },
  },
});

Default

ts
true

groups?

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.