Skip to content
Back to skills

Bundle Optimization

ASecurity

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

  • 840 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added February 7, 2026
devopsgobashvueperformance

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned February 12, 2026

npx -y skills add TencentBlueKing/bk-bcs --skill bundle-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Bundle Optimization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Bundle Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tencentblueking-bundle-optimization/badge)](https://www.skillsdirectory.com/skills/tencentblueking-bundle-optimization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: eng-bundle-opt
name: Vite 构建产物体积优化
category: engineering
description: 使用 Rollup Visualizer 分析产物,并通过拆包 (Code Splitting) 和 Tree Shaking 减少首屏体积。
tags: [vite, rollup, performance, optimization]
updated_at: 2026-01-09
---

# Vite 构建产物体积优化

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

## 1. 产物分析 (Visualizer)

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

```bash
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 压缩
```bash
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 规则判断是否需要加载

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.