# sanyuan0704/vite-plugin-chunk-split architecture

> Architecture diagram of the GitHub repository sanyuan0704/vite-plugin-chunk-split, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sanyuan0704/vite-plugin-chunk-split
- Repository: https://github.com/sanyuan0704/vite-plugin-chunk-split

## Overview

vite-plugin-chunk-split is a Vite plugin that configures Rollup chunk assignment. A developer adds the plugin and selects a strategy or custom rules; during Vite configuration, the plugin builds a manual-chunk callback that classifies modules, optionally scanning imports and resolving package entries. Rollup uses that callback during bundling. The plugin also has a separate renderChunk hook that removes imports from generated commonjs helper chunks. The map is based on the README and sampled source; no separate unsampled product subsystem is evident.

Main entry points: [`src/index.ts`](https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/index.ts) (Chunk strategy), [`src/staticImportScan.ts`](https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/staticImportScan.ts) (Static import scan), [`src/utils.ts`](https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/utils.ts) (Path and package resolution), [`src/helper.ts`](https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/helper.ts) (CSS identifier check)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_plugin["Plugin lifecycle"]
  node_plugin_entry["Plugin hooks<br/>[index.ts]"]
  node_chunk_cleanup["Helper import cleanup<br/>[index.ts]"]
end

subgraph group_splitting["Chunk splitting"]
  node_chunk_strategy["Chunk strategy<br/>[index.ts]"]
  node_custom_rules["Custom split rules<br/>[index.ts]"]
end

subgraph group_support["Classification support"]
  node_static_scan["Static import scan"]
  node_path_utils["Path and package resolution<br/>[utils.ts]"]
  node_css_check["CSS identifier check<br/>[helper.ts]"]
end

node_developer(("Plugin user"))
node_vite["Vite"]
node_rollup["Rollup bundler"]

node_developer -->|"configures"| node_plugin_entry
node_vite -->|"runs hooks"| node_plugin_entry
node_plugin_entry -->|"builds callback"| node_chunk_strategy
node_chunk_strategy -->|"wraps rules"| node_custom_rules
node_chunk_strategy -->|"scans imports"| node_static_scan
node_chunk_strategy -->|"checks CSS"| node_css_check
node_custom_rules -->|"resolves packages"| node_path_utils
node_plugin_entry -->|"sets manualChunks"| node_rollup
node_rollup -.->|"classifies modules"| node_chunk_strategy
node_vite -->|"runs render hook"| node_chunk_cleanup

click node_plugin_entry "https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/index.ts"
click node_chunk_strategy "https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/index.ts"
click node_custom_rules "https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/index.ts"
click node_static_scan "https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/staticImportScan.ts"
click node_path_utils "https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/utils.ts"
click node_css_check "https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/helper.ts"
click node_chunk_cleanup "https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/index.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_plugin_entry,node_chunk_cleanup,node_developer toneBlue
class node_chunk_strategy,node_custom_rules toneAmber
class node_static_scan,node_path_utils,node_css_check toneMint
class node_vite,node_rollup toneIndigo
```

## Components

### Plugin lifecycle

- [Plugin hooks](https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/index.ts): `src/index.ts`
- [Helper import cleanup](https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/index.ts): `src/index.ts`

### Chunk splitting

- [Chunk strategy](https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/index.ts): `src/index.ts`
- [Custom split rules](https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/index.ts): `src/index.ts`

### Classification support

- [Static import scan](https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/staticImportScan.ts): `src/staticImportScan.ts`
- [Path and package resolution](https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/utils.ts): `src/utils.ts`
- [CSS identifier check](https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/helper.ts): `src/helper.ts`

### Other components

- **Plugin user**
- **Vite**
- **Rollup bundler**

## Connections

- Plugin user → Plugin hooks: configures (evidence: `README.md`)
- Vite → Plugin hooks: runs hooks (evidence: `src/index.ts`)
- Plugin hooks → Chunk strategy: builds callback (evidence: `src/index.ts`)
- Chunk strategy → Custom split rules: wraps rules (evidence: `src/index.ts`)
- Chunk strategy → Static import scan: scans imports (evidence: `src/index.ts`)
- Chunk strategy → CSS identifier check: checks CSS (evidence: `src/index.ts`)
- Custom split rules → Path and package resolution: resolves packages (evidence: `src/index.ts`)
- Plugin hooks → Rollup bundler: sets manualChunks (evidence: `src/index.ts`)
- Rollup bundler → Chunk strategy: classifies modules
- Vite → Helper import cleanup: runs render hook (evidence: `src/index.ts`)
