OpenParable
Skip to content
← Back to skills

Vite 构建产物体积优化

Development

Vite 构建产物体积优化 is an Agent Skill for development published in the TencentBlueKing/bk-bcs repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

使用 Rollup Visualizer 分析产物,并通过拆包 (Code Splitting) 和 Tree Shaking 减少首屏体积。

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/TencentBlueKing/bk-bcs/blob/HEAD/bcs-services/bcs-project-manager/.cursor/skills/bundle-optimization/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/vite-构建产物体积优化, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Vite 构建产物体积优化

当首屏加载慢 (FCP > 1.5s) 时,通常需要检查 JS Bundle 的体积。

1. 产物分析 (Visualizer)

首先"看见"哪些包最大。

npm install rollup-plugin-visualizer -D

2. 常用优化策略

路由懒加载 (Route Lazy Loading)

这是收益最大的优化点。

❌ import UserList from './views/UserList.vue' ✅ component: () => import('./views/UserList.vue')

依赖分包 (Manual Chunks)

将大型库(ECharts, bkui-vue)单独打包,避免 vendor hash 频繁变化。

按需引入 (Tree Shaking)

❌ import _ from 'lodash' ✅ import debounce from 'lodash-es/debounce'

Gzip 压缩

npm install vite-plugin-compression -D

3. 完整配置模版

📦 获取完整 vite.config.ts 配置:skill://bundle-optimization/assets/vite.config.optimization.ts


📦 可用资源

  • skill://bundle-optimization/assets/vite.config.optimization.ts

根据 SKILL.md 中的 IF-THEN 规则判断是否需要加载