vue3-best-practices
Vue 3 Best Practices
Comprehensive performance optimization and development guide for Vue 3 applications. Contains 45 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new Vue 3 components or composables
- Implementing reactive data and computed properties
- Reviewing code for performance issues
- Refactoring from Vue 2 to Vue 3
- Optimizing bundle size or load times
- Working with state management (Pinia/Vuex)
- Implementing async operations in components
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Reactivity Performance | CRITICAL | reactivity- |
| 2 | Component Optimization | CRITICAL | component- |
| 3 | Bundle Size & Loading | HIGH | bundle- |
| 4 | Composition API | MEDIUM-HIGH | composition- |
| 5 | Template Performance | MEDIUM | template- |
| 6 | State Management | MEDIUM | state- |
| 7 | Lifecycle Optimization | LOW-MEDIUM | lifecycle- |
| 8 | Advanced Patterns | LOW | advanced- |
Quick Reference
1. Reactivity Performance (CRITICAL)
reactivity-ref-vs-reactive- Use ref for primitives, reactive for objectsreactivity-shallow-ref- Use shallowRef for large immutable objectsreactivity-computed-caching- Leverage computed property cachingreactivity-watch-vs-watcheffect- Choose appropriate watcherreactivity-unref-performance- Minimize unref calls in hot pathsreactivity-readonly-immutable- Use readonly for immutable data
2. Component Optimization (CRITICAL)
component-async-components- Use defineAsyncComponent for heavy componentscomponent-functional- Use functional components for simple presentational logiccomponent-keep-alive- Cache expensive components with keep-alivecomponent-lazy-hydration- Implement lazy hydration for non-critical componentscomponent-prop-validation- Use efficient prop validationcomponent-emit-performance- Optimize event emissions
3. Bundle Size & Loading (HIGH)
bundle-tree-shaking- Structure imports for optimal tree-shakingbundle-dynamic-imports- Use dynamic imports for code splittingbundle-plugin-imports- Use unplugin-auto-import for better DXbundle-lodash-imports- Import lodash functions individuallybundle-moment-alternatives- Use day.js instead of moment.jsbundle-icons-optimization- Optimize icon imports and usage
4. Composition API (MEDIUM-HIGH)
composition-script-setup- Prefer for better performancecomposition-composables-reuse- Extract reusable logic into composablescomposition-provide-inject- Use provide/inject for dependency injectioncomposition-expose-selectively- Expose only necessary propertiescomposition-reactive-transform- Use reactive transform where appropriatecomposition-auto-import- Configure auto-imports for better DX
5. Template Performance (MEDIUM)
template-v-once- Use v-once for static contenttemplate-v-memo- Use v-memo for expensive list renderingtemplate-key-optimization- Optimize v-for keys for performancetemplate-conditional-rendering- Choose v-if vs v-show appropriatelytemplate-slot-performance- Optimize slot usage and scoped slotstemplate-directive-optimization- Create efficient custom directives
6. State Management (MEDIUM)
state-pinia-optimization- Optimize Pinia store structurestate-store-composition- Use store composition patternsstate-persistence- Implement efficient state persistencestate-normalization- Normalize complex state structuresstate-subscription- Optimize state subscriptionsstate-devtools- Configure devtools for debugging
7. Lifecycle Optimization (LOW-MEDIUM)
lifecycle-cleanup- Properly cleanup resources in onUnmountedlifecycle-async-setup- Handle async operations in setuplifecycle-watchers-cleanup- Clean up watchers and effectslifecycle-dom-access- Access DOM safely in lifecycle hookslifecycle-ssr-considerations- Handle SSR lifecycle differences
8. Advanced Patterns (LOW)
advanced-teleport-usage- Use Teleport for portal patternsadvanced-suspense-async- Implement Suspense with async componentsadvanced-custom-renderer- Create custom renderers when neededadvanced-compiler-macros- Use compiler macros effectivelyadvanced-plugin-development- Develop efficient Vue plugins
Framework Integration
Vite Integration
- Utilize Vite's fast HMR and build optimizations
- Configure proper chunk splitting strategies
- Use Vite plugins for Vue-specific optimizations
TypeScript Integration
- Leverage Vue 3's improved TypeScript support
- Use proper type definitions for better DX
- Configure TypeScript for optimal build performance
Testing Integration
- Use Vue Test Utils with Composition API
- Implement efficient component testing strategies
- Optimize test performance and reliability
How to Use
Read individual rule files for detailed explanations and code examples:
rules/reactivity-ref-vs-reactive.md
rules/component-async-components.md
rules/composition-script-setup.md
Each rule file contains:
- Brief explanation of why it matters
- Incorrect Vue 3 code example with explanation
- Correct Vue 3 code example with explanation
- Performance impact and measurements
- Additional context and Vue 3-specific considerations
Migration from Vue 2
Special considerations for migrating from Vue 2:
- Composition API vs Options API patterns
- Reactivity system changes and optimizations
- Component definition and registration updates
- Event handling and lifecycle changes
Performance Monitoring
Tools and techniques for monitoring Vue 3 performance:
- Vue DevTools integration
- Performance profiling with browser tools
- Bundle analysis and optimization
- Runtime performance monitoring
More from eva813/vue3-skills
frontend-design
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.
4react-agent
Pragmatic React development focused on avoiding over-engineering, effective state management, and render optimization. Use when building React components or features where you need clear guidance on (1) choosing appropriate state management solutions, (2) optimizing component rendering and performance, (3) avoiding common over-engineering patterns, (4) implementing TypeScript with React, or (5) making architectural decisions that balance simplicity with scalability.
3git-conventional-commits
Professional git commit workflow with Conventional Commits format. Enforces commit type categorization (feat, fix, docs, style, refactor, perf, test, build, ci, chore), validates messages against the 7 rules of great commits, previews before committing, and supports multiple languages. Use when you need to create high-quality, traceable git commits.
3web-design-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
3vercel-react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
3vercel-composition-patterns
React composition patterns that scale. Use when refactoring components with
3