Skip to content
Skillv1.0.0

Vite 构建产物体积优化

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

by TencentBlueKing(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from TencentBlueKing/bk-bcs (bcs-services/bcs-project-manager/.cursor/skills/bundle-optimization/SKILL.md). Install upstream with npx skills add TencentBlueKing/bk-bcs --skill bundle-optimization. Copyright stays with the author.

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

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/tencentblueking-bk-bcs-bundle-optimization/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

tencentblueking-bk-bcs-bundle-optimization.ocm.jsonjson
{
  "ocm": "1",
  "id": "tencentblueking-bk-bcs-bundle-optimization",
  "kind": "skill",
  "name": "Vite 构建产物体积优化",
  "description": "使用 Rollup Visualizer 分析产物,并通过拆包 (Code Splitting) 和 Tree Shaking 减少首屏体积。",
  "publisher": "TencentBlueKing",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "vite",
      "rollup",
      "performance",
      "optimization",
      "github"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "使用 Rollup Visualizer 分析产物,并通过拆包 (Code Splitting) 和 Tree Shaking 减少首屏体积。"
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "github",
      "repository": "https://github.com/TencentBlueKing/bk-bcs",
      "path": "bcs-services/bcs-project-manager/.cursor/skills/bundle-optimization/SKILL.md",
      "ref": "445c155ee28ee83a707ec81306383e1cc9708dd2",
      "url": "https://github.com/TencentBlueKing/bk-bcs/blob/445c155ee28ee83a707ec81306383e1cc9708dd2/bcs-services/bcs-project-manager/.cursor/skills/bundle-optimization/SKILL.md",
      "key": "TencentBlueKing/bk-bcs/bcs-services/bcs-project-manager/.cursor/skills/bundle-optimization/SKILL.md"
    }
  },
  "instructions": "# Vite 构建产物体积优化\n\n当首屏加载慢 (FCP > 1.5s) 时,通常需要检查 JS Bundle 的体积。\n\n## 1. 产物分析 (Visualizer)\n\n首先\"看见\"哪些包最大。\n\n```bash\nnpm install rollup-plugin-visualizer -D\n```\n\n## 2. 常用优化策略\n\n### 路由懒加载 (Route Lazy Loading)\n**这是收益最大的优化点**。\n\n❌ `import UserList from './views/UserList.vue'`\n✅ `component: () => import('./views/UserList.vue')`\n\n### 依赖分包 (Manual Chunks)\n将大型库(ECharts, bkui-vue)单独打包,避免 vendor hash 频繁变化。\n\n### 按需引入 (Tree Shaking)\n❌ `import _ from 'lodash'`\n✅ `import debounce from 'lodash-es/debounce'`\n\n### Gzip 压缩\n```bash\nnpm install vite-plugin-compression -D\n```\n\n## 3. 完整配置模版\n\n> 📦 获取完整 vite.config.ts 配置:`skil",
  "cost": {
    "context_tokens": 195
  }
}

Fetch it by URL: GET /api/v1/registry/tencentblueking-bk-bcs-bundle-optimization/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.