aicode8
viteperformance-optimization更新于 2026-09-10

Vite 打包优化

围绕 Vite 的真实打包瓶颈,给出可落地的拆包、预构建与长效缓存清单。

生产环境配置

vite 6.x

vite.config.ts — build target + sourcemap disable

import { defineConfig } from 'vite';

export default defineConfig({
  build: {
    target: 'es2022',
    sourcemap: false,
    cssCodeSplit: true,
  },
});

同一份配置,换运行时

[install]
exact = true
frozenLockfile = true

[run]
bun = true

verified bun 1.1.x

Core Failure Surface

围绕 Vite 的真实打包瓶颈,给出可落地的拆包、预构建与长效缓存清单。

Production Configuration

Verified against vite 6.x. vite.config.ts — build target + sourcemap disable

import { defineConfig } from 'vite';

export default defineConfig({
  build: {
    target: 'es2022',
    sourcemap: false,
    cssCodeSplit: true,
  },
});

Troubleshooting Nodes

Vite manualChunks 配错会造成什么问题?

写错会把样式误打进 JS 或造成循环依赖,首屏体积反升;应先按 vendor 粗拆,再逐步细化。

Vite 构建产物在边缘如何做长缓存?

把内容哈希文件名资源设为 immutable 长缓存、入口 HTML 设为 must-revalidate;变更文件名即换 URL,天然规避缓存击穿。

Verification Gate

Every asset in this matrix must pass a full static build before it is eligible for manual review. Automated publishing is disabled by design.

常见问题与避坑

Vite manualChunks 配错会造成什么问题?

写错会把样式误打进 JS 或造成循环依赖,首屏体积反升;应先按 vendor 粗拆,再逐步细化。

Vite 构建产物在边缘如何做长缓存?

把内容哈希文件名资源设为 immutable 长缓存、入口 HTML 设为 must-revalidate;变更文件名即换 URL,天然规避缓存击穿。