--- name: vue3-best-practices description: Vue 3 performance optimization and best practices guidelines for modern frontend applications. This skill should be used when writing, reviewing, or refactoring Vue 3 code to ensure optimal performance patterns, proper Composition API usage, and modern development practices. Triggers on tasks involving Vue 3 components, Composition API, reactivity, state management, or performance optimization. license: MIT metadata: author: Eva version: "1.0.0" --- # 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 objects - `reactivity-shallow-ref` - Use shallowRef for large immutable objects - `reactivity-computed-caching` - Leverage computed property caching - `reactivity-watch-vs-watcheffect` - Choose appropriate watcher - `reactivity-unref-performance` - Minimize unref calls in hot paths - `reactivity-readonly-immutable` - Use readonly for immutable data ### 2. Component Optimization (CRITICAL) - `component-async-components` - Use defineAsyncComponent for heavy components - `component-functional` - Use functional components for simple presentational logic - `component-keep-alive` - Cache expensive components with keep-alive - `component-lazy-hydration` - Implement lazy hydration for non-critical components - `component-prop-validation` - Use efficient prop validation - `component-emit-performance` - Optimize event emissions ### 3. Bundle Size & Loading (HIGH) - `bundle-tree-shaking` - Structure imports for optimal tree-shaking - `bundle-dynamic-imports` - Use dynamic imports for code splitting - `bundle-plugin-imports` - Use unplugin-auto-import for better DX - `bundle-lodash-imports` - Import lodash functions individually - `bundle-moment-alternatives` - Use day.js instead of moment.js - `bundle-icons-optimization` - Optimize icon imports and usage ### 4. Composition API (MEDIUM-HIGH) - `composition-script-setup` - Prefer