Splitting Vite vendor bundles with Rollup manualChunks
Group React, UI, charts, and utilities into Rollup chunks, inspect cache reuse and cyclic dependencies, and account for the Vite 8 migration.
A vendor chunk can improve repeat-visit caching when its contents change less often than application code. In this Vite example I use Rollup’s
manualChunksto separate stable dependency groups, then check that the split preserves lazy loading and module initialization order.
Read the bundle warning as a symptom
1
2
3
(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking
Figure 1. The entry chunk includes application code and dependencies used by later routes.
A single file can make the browser fetch chart widgets, editors, and other route-specific dependencies before the home page can render. It can also invalidate all cached vendor code when an application change updates the filename hash. Raising the warning limit changes the log. Inspect the size and request path before deciding what to move.
Use boundaries that reflect actual changes
flowchart TD
subgraph SingleBundle["Before: one bundle"]
A["index-D8x2aQ.js (1.4MB)"]
A --> A1["React + Router"]
A --> A2["UI libraries (AntD/MUI)"]
A --> A3["ECharts / D3"]
A --> A4["Application code"]
NoteA["One application edit invalidates the 1.4 MB file"]
end
subgraph ChunkSplitting["After: vendor chunks"]
B1["vendor-react-[hash].js (138kB)"]
B2["vendor-ui-[hash].js (242kB)"]
B3["vendor-charts-[hash].js (312kB)"]
B4["index-[hash].js (145kB)"]
NoteB["An application edit can invalidate just index-[hash].js (145 kB)"]
end
Content-hashed files can use long-lived caching if the server returns an appropriate policy. A later deployment can reuse a vendor chunk when its name and content stay unchanged. Chunk references can affect hashes too, so changing an application file does not guarantee that exactly one generated file changes.
I start by separating dependencies with a different release and usage pattern. Framework code that every route needs can be a stable group. A large chart library that renders on one route is a candidate for a lazy chunk. Too many small files have their own fetch and parsing costs, so I check the network graph after grouping.
Choose an object map or a callback
The Rollup object form maps chunk names to explicit module IDs. The bundler can include dependencies of the listed modules as it constructs each manual chunk. That is convenient for a few stable groups, but it can pull an unexpected module into a group shared across several dependencies.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// vite.config.ts
import { defineConfig } from 'vite';
export default defineConfig({
build: {
rollupOptions: {
output: {
manualChunks: {
'vendor-react': ['react', 'react-dom', 'react-router-dom'],
'vendor-utils': ['lodash-es', 'dayjs', 'axios']
}
}
}
}
});
A callback can inspect the resolved module ID and return a chunk name. This gives me more control over the graph, particularly when a package family shares internal modules. In the sample below, framework, charts, components, and utilities have distinct branches. An ID that does not match falls back to the bundler’s ordinary strategy.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
build: {
target: 'es2020',
chunkSizeWarningLimit: 600, // Warn for chunks over 600 kB
rollupOptions: {
output: {
manualChunks(id) {
// Only group dependencies from node_modules
if (id.includes('node_modules')) {
// 1. React framework core
if (
id.includes('/react/') ||
id.includes('/react-dom/') ||
id.includes('/react-router-dom/')
) {
return 'vendor-react';
}
// 2. Visualization and chart libraries
if (
id.includes('/echarts/') ||
id.includes('/zrender/') ||
id.includes('/d3/')
) {
return 'vendor-charts';
}
// 3. UI component frameworks such as Ant Design and MUI
if (
id.includes('/antd/') ||
id.includes('/@ant-design/') ||
id.includes('/@emotion/')
) {
return 'vendor-ui';
}
// 4. Shared utilities
if (
id.includes('/lodash/') ||
id.includes('/lodash-es/') ||
id.includes('/dayjs/') ||
id.includes('/axios/')
) {
return 'vendor-utils';
}
// Let Rollup handle other dependencies
return 'vendor-libs';
}
}
}
}
}
});
Check the Vite version before copying the configuration. Vite 8 uses Rolldown, exposes
build.rolldownOptions, and its compatibility formanualChunksdiffers from Rollup’s. The object form is unavailable there. Use the migration guide to choose the callback form or Rolldown’s native splitting options.
Keep lazy routes and dependency cycles visible
1
2
(!) Circular dependency:
vendor-react -> vendor-ui -> vendor-react
An explicit grouping can introduce a cycle between chunks or move a module with top-level effects earlier than expected. Keep tightly coupled packages together when that matches their graph. @tanstack/react-query and @tanstack/query-core are an example of packages to inspect as a group.
A dependency used only by a lazy route should remain eligible for loading with that route. I leave such modules out of broad vendor patterns unless I have measured a reason to share them globally. See the companion route splitting example for the network behavior this preserves.
Verify the built files and cache behavior
Figure 2. The sample Rollup build emits separate vendor groups and a smaller application entry.
| Output | Minified size | Gzip |
|---|---|---|
vendor-react-C8k2.js | 138.42 kB | 44.18 kB |
vendor-ui-B5m1.js | 242.11 kB | 68.40 kB |
vendor-charts-F3x9.js | 312.80 kB | 89.15 kB |
vendor-utils-A9q4.js | 84.22 kB | 24.10 kB |
index-E7d1.js | 145.29 kB | 39.75 kB |
The entry file in this build is about 145 kB. Add the files actually requested by the home route to measure its full download. To check repeat-visit caching, rebuild after a small application change, compare file hashes, then inspect the browser on the updated deployment.
Recheck the split when changing bundlers
Vite 7 runs these chunk options through Rollup. Vite 8 uses Rolldown’s Rust-based build pipeline and changes some options and chunking behavior. Performance depends on the graph, plugins, source maps, and machine. Verify the resulting entry, lazy imports, and cyclic warnings on the new toolchain. Vite migration guide