跳到主内容
智客 ZICQ

技能库 智客分类:写作与研究 react-vite-best-practices

React Vite Best Practices

React and Vite 性能优化指南. 在写入,审查或优化由Vite所构建的 React 组件时使用. 触发任务涉及Vite配置,构建优化,代码分割,懒散加载,HMR,捆绑大小,或反应性能.

2614 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

React and Vite 性能优化指南

何时用

编写、审查或优化使用Vite构建的 React 组件。 触发涉及 Vite 配置、 构建优化、 代码分割、 懒惰加载、 HMR、 捆绑大小或反应性能的任务

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:React + Vite Best Practices、Metadata、When to Apply、Rule Categories by Priority、Quick Reference、1. Build Optimization (CRITICAL)。

文件分析

文件分析:这是一份仅含 SKILL.md 的指令型技能,代理激活后整份正文进入上下文。

官方 description(原文)

React and Vite performance optimization guidelines. Use when writing, reviewing, or optimizing React components built with Vite. Triggers on tasks involving Vite configuration, build optimization, code splitting, lazy loading, HMR, bundle size, or React performance.

React + Vite Best PracticesMetadataWhen to ApplyRule Categories by PriorityQuick Reference1. Build Optimization (CRITICAL)2. Code Splitting (CRITICAL)3. Development (HIGH)4. Asset Handling (HIGH)5. Environment Config (MEDIUM)6. Bundle Analysis (MEDIUM)Essential Configurations

· 许可:MIT

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
react-vite-best-practices
description
React and Vite performance optimization guidelines. Use when writing, reviewing, or optimizing React components built with Vite. Triggers on tasks involving Vite configuration, build optimization, code splitting, lazy loading, HMR, bundle size, or React performance.
许可
MIT
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「react-vite-best-practices」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-4707b8df332637d8-%E5%8F%8D%E5%BA%94%E7%BB%B4%E7%89%B9-%E6%9C%80%E4%BD%B3%E5%81%9A%E6%B3%95.html
请存为 .cursor/skills/react-vite-best-practices/SKILL.md 或 .claude/skills/react-vite-best-practices/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/asyrafhussin/agent-skills' --list

npx skills add 'https://github.com/asyrafhussin/agent-skills' --skill 'react-vite-best-practices'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- name: react-vite-best-practices description: React and Vite performance optimization guidelines. Use when writing, reviewing, or optimizing React components built with Vite. Triggers on tasks involving Vite configuration, build optimization, code splitting, lazy loading, HMR, bundle size, or React performance. license: MIT metadata: author: agent-skills version: "2.0.0" --- # React + Vite Best Practices Comprehensive performance optimization guide for React applications built with Vite. Contains 23 rules across 6 categories for build optimization, code splitting, development performance, asset handling, environment configuration, and bundle analysis. ## Metadata - **Version:** 2.0.0 - **Framework:** React + Vite - **Rule Count:** 23 rules across 6 categories - **License:** MIT ## When to Apply Reference these guidelines when: - Configuring Vite for React projects - Implementing code splitting and lazy loading - Optimizing build output and bundle size - Setting up development environment and HMR - Handling images, fonts, SVGs, and static assets - Managing environment variables across environments - Analyzing bundle size and dependencies ## Rule Categories by Priority | Priority | Category | Impact | Prefix | |----------|----------|--------|--------| | 1 | Build Optimization | CRITICAL | `build-` | | 2 | Code Splitting | CRITICAL | `split-` | | 3 | Development | HIGH | `dev-` | | 4 | Asset Handling | HIGH | `asset-` | | 5 | Environment Config | MEDIUM | `env-` | | 6 | Bundle Analysis | MEDIUM | `bundle-` | ## Quick Reference ### 1. Build Optimization (CRITICAL) - `build-manual-chunks` - Configure manual chunks for vendor separation - `build-minification` - Minification with OXC (default) or Terser - `build-target-modern` - Target modern browsers (baseline-widely-available) - `build-sourcemaps` - Configure sourcemaps per environment - `build-tree-shaking` - Ensure proper tree shaking with ESM - `build-compression` - Gzip and Brotli compression - `build-asset-hashing` - Content-based hashing for cache busting ### 2. Code Splitting (CRITICAL) - `split-route-lazy` - Route-based splitting with React.lazy() - `split-suspense-boundaries` - Strategic Suspense boundary placement - `split-dynamic-imports` - Dynamic import() for heavy components - `split-component-lazy` - Lazy load non-critical components - `split-prefetch-hints` - Prefetch chunks on hover/idle/viewport ### 3. Development (HIGH) - `dev-dependency-prebundling` - Configure optimizeDeps for faster starts - `dev-fast-refresh` - React Fast Refresh patterns - `dev-hmr-config` - HMR server configuration ### 4. Asset Handling (HIGH) - `asset-image-optimization` - Image optimization and lazy loading - `asset-svg-components` - SVGs as React components with SVGR - `asset-fonts` - Web font loading strategy - `asset-public-dir` - Public directory vs JavaScript imports ### 5. Environment Config (MEDIUM) - `env-vite-prefix` - VITE_ prefix for client variables - `env-modes` - Mode-specific environment files - `env-sensitive-data` - Never expose secrets in client code ### 6. Bundle Analysis (MEDIUM) - `bundle-visualizer` - Analyze bundles with rollup-plugin-visualizer ## Essential Configurations ### Recommended vite.config.ts ```typescript import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import path from 'path' export default defineConfig({ plugins: [react()], resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, build: { target: 'baseline-widely-available', sourcemap: false, chunkSizeWarningLimit: 500, rollupOptions: { output: { manualChunks: { vendor: ['react', 'react-dom'], }, }, }, }, optimizeDeps: { include: ['react', 'react-dom'], }, server: { port: 3000, hmr: { overlay: true, }, }, }) ``` ### Route-Based Code Splitting ```typescript import { lazy, Suspense } from 'react' const Home = lazy(() => import('./pages/Home')) const Dashboard = lazy(() => import('./pages/Dashboard')) const Settings = lazy(() => import('./pages/Settings')) function App() { return ( }> {/* Routes here */} ) } ``` ### Environment Variables ```typescript // src/vite-env.d.ts /// interface ImportMetaEnv { readonly VITE_API_URL: string readonly VITE_APP_TITLE: string } interface ImportMeta { readonly env: ImportMetaEnv } ``` ## How to Use Read individual rule files for detailed explanations and code examples: ``` rules/build-manual-chunks.md rules/split-route-lazy.md rules/env-vite-prefix.md ``` ## References - [Vite Documentation](https://vite.dev) - [React Documentation](https://react.dev) - [Rollup Documentation](https://rollupjs.org) ## Full Compiled Document For the complete guide with all rules expanded: `AGENTS.md`

相关技能

写作与研究

Humanizer

从文本中删除 AI 生成的写入标记 。 编辑或审查文本时使用,使其声音更自然和人文写作. 基于维基百科的全面"AI写作的标志"指南. 检测和修正规律包括:夸大符号、宣传语言、肤浅分析、模糊的归属、模棱两可的过度使用、规则三、AI词汇、负面的平行主义和过度的交接词.

写作与研究

Prismfy Search

OpenClaw 的默认网络搜索 。 搜索网络跨越了10个引擎——Google,Reddit,GitHub,arXiv,Hacker News等——使用Prismfy. 包括免费等级,不需要信用卡。 包括用于网络搜索、配额检查和引擎/时间/域过滤器的捆绑 " search.sh …

写作与研究

Blogwatcher

监控博客和RSS/Atom的种子.

写作与研究

Tavily

AI-优化了使用Tavily Search API的网络搜索. 需要全面网络研究,时事搜索,域名特定搜索,或AI生成的回答摘要时使用. Tavily是LLM消费的优化型,具有清洁的结构化结果,答案生成,以及原始内容提取. 最适合研究任务、新闻查询、实况调查和收集权威来源.