claude-mpm 4.17.0__py3-none-any.whl → 4.17.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of claude-mpm might be problematic. Click here for more details.

Files changed (27) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/skills/bundled/api-documentation.md +393 -0
  3. claude_mpm/skills/bundled/async-testing.md +571 -0
  4. claude_mpm/skills/bundled/code-review.md +143 -0
  5. claude_mpm/skills/bundled/database-migration.md +199 -0
  6. claude_mpm/skills/bundled/docker-containerization.md +194 -0
  7. claude_mpm/skills/bundled/express-local-dev.md +1429 -0
  8. claude_mpm/skills/bundled/fastapi-local-dev.md +1199 -0
  9. claude_mpm/skills/bundled/git-workflow.md +414 -0
  10. claude_mpm/skills/bundled/imagemagick.md +204 -0
  11. claude_mpm/skills/bundled/json-data-handling.md +223 -0
  12. claude_mpm/skills/bundled/nextjs-local-dev.md +807 -0
  13. claude_mpm/skills/bundled/pdf.md +141 -0
  14. claude_mpm/skills/bundled/performance-profiling.md +567 -0
  15. claude_mpm/skills/bundled/refactoring-patterns.md +180 -0
  16. claude_mpm/skills/bundled/security-scanning.md +327 -0
  17. claude_mpm/skills/bundled/systematic-debugging.md +473 -0
  18. claude_mpm/skills/bundled/test-driven-development.md +378 -0
  19. claude_mpm/skills/bundled/vite-local-dev.md +1061 -0
  20. claude_mpm/skills/bundled/web-performance-optimization.md +2305 -0
  21. claude_mpm/skills/bundled/xlsx.md +157 -0
  22. {claude_mpm-4.17.0.dist-info → claude_mpm-4.17.1.dist-info}/METADATA +1 -1
  23. {claude_mpm-4.17.0.dist-info → claude_mpm-4.17.1.dist-info}/RECORD +27 -7
  24. {claude_mpm-4.17.0.dist-info → claude_mpm-4.17.1.dist-info}/WHEEL +0 -0
  25. {claude_mpm-4.17.0.dist-info → claude_mpm-4.17.1.dist-info}/entry_points.txt +0 -0
  26. {claude_mpm-4.17.0.dist-info → claude_mpm-4.17.1.dist-info}/licenses/LICENSE +0 -0
  27. {claude_mpm-4.17.0.dist-info → claude_mpm-4.17.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1061 @@
1
+ ---
2
+ skill_id: vite-local-dev
3
+ skill_version: 0.1.0
4
+ description: Maximizing Vite's development server performance, managing HMR effectively, and avoiding process management pitfalls.
5
+ updated_at: 2025-10-30T17:00:00Z
6
+ tags: [vite, development, hmr, frontend, build-tool]
7
+ ---
8
+
9
+ # Vite Local Development Server
10
+
11
+ ## Overview
12
+
13
+ Vite is a next-generation frontend build tool that provides blazing-fast Hot Module Replacement (HMR) and optimized builds. It leverages native ES modules during development and Rollup for production builds. This skill focuses on maximizing Vite's development server performance, managing HMR effectively, and avoiding process management pitfalls.
14
+
15
+ ## When to Use This Skill
16
+
17
+ - Setting up Vite development environment
18
+ - Optimizing HMR and development server performance
19
+ - Troubleshooting HMR connection issues
20
+ - Configuring Vite for different frontend frameworks (React, Vue, Svelte)
21
+ - Managing proxy configuration for API backends
22
+ - Resolving WebSocket and CORS issues
23
+ - Understanding when NOT to use PM2 with Vite dev server
24
+
25
+ ## Quick Start
26
+
27
+ ### Development Server
28
+
29
+ **Basic Vite Development:**
30
+ ```bash
31
+ # Start dev server
32
+ npm run dev
33
+ # or
34
+ yarn dev
35
+ # or
36
+ pnpm dev
37
+ ```
38
+
39
+ **Custom Port and Host:**
40
+ ```bash
41
+ # CLI flags
42
+ npm run dev -- --port 3001 --host 0.0.0.0
43
+
44
+ # Or set in package.json
45
+ ```
46
+
47
+ **Force Optimization:**
48
+ ```bash
49
+ # Force dependency pre-bundling
50
+ npm run dev -- --force
51
+ ```
52
+
53
+ **Open in Browser:**
54
+ ```bash
55
+ # Automatically open browser
56
+ npm run dev -- --open
57
+ ```
58
+
59
+ ### Basic Vite Config
60
+
61
+ ```javascript
62
+ // vite.config.js
63
+ import { defineConfig } from 'vite';
64
+ import react from '@vitejs/plugin-react';
65
+
66
+ export default defineConfig({
67
+ plugins: [react()],
68
+ server: {
69
+ port: 3000,
70
+ host: true, // Listen on all addresses
71
+ open: true, // Auto-open browser
72
+ },
73
+ build: {
74
+ outDir: 'dist',
75
+ sourcemap: true,
76
+ },
77
+ });
78
+ ```
79
+
80
+ ### With Docker
81
+
82
+ **Development Dockerfile:**
83
+ ```dockerfile
84
+ FROM node:18-alpine
85
+
86
+ WORKDIR /app
87
+
88
+ COPY package*.json ./
89
+ RUN npm install
90
+
91
+ COPY . .
92
+
93
+ EXPOSE 5173
94
+
95
+ CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
96
+ ```
97
+
98
+ **Docker Compose:**
99
+ ```yaml
100
+ version: '3.8'
101
+
102
+ services:
103
+ vite-app:
104
+ build: .
105
+ ports:
106
+ - "5173:5173"
107
+ volumes:
108
+ - .:/app
109
+ - /app/node_modules
110
+ environment:
111
+ - NODE_ENV=development
112
+ - CHOKIDAR_USEPOLLING=false
113
+ command: npm run dev -- --host 0.0.0.0
114
+ ```
115
+
116
+ ## Configuration Patterns
117
+
118
+ ### HMR Configuration and Optimization
119
+
120
+ **Vite HMR Settings:**
121
+ ```javascript
122
+ // vite.config.js
123
+ export default defineConfig({
124
+ server: {
125
+ hmr: {
126
+ protocol: 'ws',
127
+ host: 'localhost',
128
+ port: 5173,
129
+ // For Docker or reverse proxy
130
+ clientPort: 5173,
131
+ },
132
+ },
133
+ });
134
+ ```
135
+
136
+ **HMR with Reverse Proxy:**
137
+ ```javascript
138
+ // vite.config.js
139
+ export default defineConfig({
140
+ server: {
141
+ hmr: {
142
+ protocol: 'wss', // Use secure WebSocket
143
+ host: 'your-domain.com',
144
+ clientPort: 443,
145
+ },
146
+ },
147
+ });
148
+ ```
149
+
150
+ **HMR Overlay Configuration:**
151
+ ```javascript
152
+ // vite.config.js
153
+ export default defineConfig({
154
+ server: {
155
+ hmr: {
156
+ overlay: true, // Show error overlay
157
+ },
158
+ },
159
+ });
160
+ ```
161
+
162
+ **Disable HMR (Not Recommended):**
163
+ ```javascript
164
+ // Only for debugging HMR issues
165
+ export default defineConfig({
166
+ server: {
167
+ hmr: false,
168
+ },
169
+ });
170
+ ```
171
+
172
+ ### WebSocket Proxy Setup
173
+
174
+ **API Proxy Configuration:**
175
+ ```javascript
176
+ // vite.config.js
177
+ export default defineConfig({
178
+ server: {
179
+ proxy: {
180
+ // Proxy API requests
181
+ '/api': {
182
+ target: 'http://localhost:4000',
183
+ changeOrigin: true,
184
+ rewrite: (path) => path.replace(/^\/api/, ''),
185
+ },
186
+ // Proxy WebSocket connections
187
+ '/ws': {
188
+ target: 'ws://localhost:4000',
189
+ ws: true,
190
+ },
191
+ },
192
+ },
193
+ });
194
+ ```
195
+
196
+ **Advanced Proxy with Custom Logic:**
197
+ ```javascript
198
+ // vite.config.js
199
+ export default defineConfig({
200
+ server: {
201
+ proxy: {
202
+ '/api': {
203
+ target: 'http://localhost:4000',
204
+ changeOrigin: true,
205
+ secure: false,
206
+ configure: (proxy, options) => {
207
+ // Custom proxy configuration
208
+ proxy.on('error', (err, req, res) => {
209
+ console.log('proxy error', err);
210
+ });
211
+ proxy.on('proxyReq', (proxyReq, req, res) => {
212
+ console.log('Sending Request:', req.method, req.url);
213
+ });
214
+ proxy.on('proxyRes', (proxyRes, req, res) => {
215
+ console.log('Received Response:', proxyRes.statusCode, req.url);
216
+ });
217
+ },
218
+ },
219
+ },
220
+ },
221
+ });
222
+ ```
223
+
224
+ **CORS Configuration:**
225
+ ```javascript
226
+ // vite.config.js
227
+ export default defineConfig({
228
+ server: {
229
+ cors: true, // Enable CORS for all origins
230
+ // Or specify origins
231
+ cors: {
232
+ origin: ['http://localhost:3000', 'https://example.com'],
233
+ credentials: true,
234
+ },
235
+ },
236
+ });
237
+ ```
238
+
239
+ ### Pre-bundling Dependencies
240
+
241
+ **Dependency Optimization:**
242
+ ```javascript
243
+ // vite.config.js
244
+ export default defineConfig({
245
+ optimizeDeps: {
246
+ // Include dependencies that should be pre-bundled
247
+ include: ['react', 'react-dom', 'lodash-es'],
248
+ // Exclude dependencies from pre-bundling
249
+ exclude: ['@custom/local-package'],
250
+ // Force pre-bundle even if cached
251
+ force: false,
252
+ },
253
+ });
254
+ ```
255
+
256
+ **Why Pre-bundling Matters:**
257
+ - Converts CommonJS/UMD to ESM
258
+ - Reduces network requests by bundling many modules
259
+ - Improves initial page load performance
260
+
261
+ **Clear Pre-bundle Cache:**
262
+ ```bash
263
+ # Delete Vite cache
264
+ rm -rf node_modules/.vite
265
+
266
+ # Restart with force flag
267
+ npm run dev -- --force
268
+ ```
269
+
270
+ ### WSL2 Specific Configuration
271
+
272
+ **File Watching in WSL2:**
273
+
274
+ WSL2 has limitations with file system events across Windows-Linux boundary.
275
+
276
+ **Option 1: Use Polling (Simple but CPU-intensive)**
277
+ ```javascript
278
+ // vite.config.js
279
+ export default defineConfig({
280
+ server: {
281
+ watch: {
282
+ usePolling: true,
283
+ interval: 1000, // Check every second
284
+ },
285
+ },
286
+ });
287
+ ```
288
+
289
+ **Option 2: Project in WSL Filesystem (Recommended)**
290
+ ```bash
291
+ # Store project in Linux filesystem, not /mnt/c/
292
+ cd ~/projects
293
+ git clone <repo>
294
+ npm install
295
+ npm run dev
296
+ ```
297
+
298
+ **Option 3: Environment Variable**
299
+ ```bash
300
+ # Set polling via environment
301
+ CHOKIDAR_USEPOLLING=true npm run dev
302
+ ```
303
+
304
+ **Performance Consideration:**
305
+ - Polling increases CPU usage
306
+ - Native WSL2 filesystem is 10-20x faster
307
+ - Avoid crossing Windows-Linux filesystem boundary
308
+
309
+ ### Performance Optimization
310
+
311
+ **Optimize Large Projects:**
312
+ ```javascript
313
+ // vite.config.js
314
+ export default defineConfig({
315
+ server: {
316
+ // Increase file size limit for large files
317
+ fs: {
318
+ strict: false, // Allow serving files outside root
319
+ },
320
+ },
321
+ optimizeDeps: {
322
+ // Pre-bundle heavy dependencies
323
+ include: [
324
+ 'react',
325
+ 'react-dom',
326
+ 'react-router-dom',
327
+ '@mui/material',
328
+ 'lodash-es',
329
+ ],
330
+ },
331
+ build: {
332
+ // Production optimizations
333
+ rollupOptions: {
334
+ output: {
335
+ manualChunks: {
336
+ vendor: ['react', 'react-dom'],
337
+ ui: ['@mui/material'],
338
+ },
339
+ },
340
+ },
341
+ },
342
+ });
343
+ ```
344
+
345
+ **Reduce Bundle Size:**
346
+ ```javascript
347
+ // vite.config.js
348
+ export default defineConfig({
349
+ build: {
350
+ minify: 'terser',
351
+ terserOptions: {
352
+ compress: {
353
+ drop_console: true, // Remove console.logs in production
354
+ },
355
+ },
356
+ // Chunk size warnings
357
+ chunkSizeWarningLimit: 1000,
358
+ },
359
+ });
360
+ ```
361
+
362
+ **Tree Shaking Optimization:**
363
+
364
+ Use named imports for better tree shaking:
365
+ ```javascript
366
+ // Bad - imports entire library
367
+ import _ from 'lodash';
368
+
369
+ // Good - tree-shakeable
370
+ import { debounce } from 'lodash-es';
371
+
372
+ // Best - direct import
373
+ import debounce from 'lodash-es/debounce';
374
+ ```
375
+
376
+ ### Named vs Default Exports for HMR
377
+
378
+ **Best Practice: Use Named Exports**
379
+
380
+ Default exports can cause HMR issues in some cases:
381
+
382
+ ```javascript
383
+ // Not ideal for HMR
384
+ export default function MyComponent() {
385
+ return <div>Hello</div>;
386
+ }
387
+
388
+ // Better for HMR
389
+ export function MyComponent() {
390
+ return <div>Hello</div>;
391
+ }
392
+
393
+ // Usage
394
+ import { MyComponent } from './MyComponent';
395
+ ```
396
+
397
+ **Why Named Exports Are Better:**
398
+ - More predictable HMR behavior
399
+ - Better tree shaking
400
+ - Easier refactoring and IDE support
401
+ - Less ambiguity in module imports
402
+
403
+ **React Fast Refresh Compatibility:**
404
+ ```javascript
405
+ // Component with named export (preferred)
406
+ export function Counter() {
407
+ const [count, setCount] = useState(0);
408
+ return <button onClick={() => setCount(count + 1)}>{count}</button>;
409
+ }
410
+
411
+ // With HMR preservation
412
+ if (import.meta.hot) {
413
+ import.meta.hot.accept();
414
+ }
415
+ ```
416
+
417
+ ### Environment Variables
418
+
419
+ **Vite Environment Variables:**
420
+
421
+ ```bash
422
+ # .env
423
+ VITE_API_URL=http://localhost:4000
424
+ VITE_APP_TITLE=My App
425
+
426
+ # .env.local (not committed)
427
+ VITE_SECRET_KEY=super-secret
428
+ ```
429
+
430
+ **Access in Code:**
431
+ ```javascript
432
+ // Only VITE_* variables are exposed to client
433
+ const apiUrl = import.meta.env.VITE_API_URL;
434
+ const mode = import.meta.env.MODE; // 'development' or 'production'
435
+ const isDev = import.meta.env.DEV; // boolean
436
+ const isProd = import.meta.env.PROD; // boolean
437
+ ```
438
+
439
+ **Type Safety with TypeScript:**
440
+ ```typescript
441
+ // vite-env.d.ts
442
+ /// <reference types="vite/client" />
443
+
444
+ interface ImportMetaEnv {
445
+ readonly VITE_API_URL: string;
446
+ readonly VITE_APP_TITLE: string;
447
+ }
448
+
449
+ interface ImportMeta {
450
+ readonly env: ImportMetaEnv;
451
+ }
452
+ ```
453
+
454
+ **Load Order:**
455
+ 1. `.env.local` (highest priority)
456
+ 2. `.env.[mode].local`
457
+ 3. `.env.[mode]`
458
+ 4. `.env`
459
+
460
+ ## Framework-Specific Best Practices
461
+
462
+ ### React with Vite
463
+
464
+ **Plugin Configuration:**
465
+ ```javascript
466
+ // vite.config.js
467
+ import { defineConfig } from 'vite';
468
+ import react from '@vitejs/plugin-react';
469
+
470
+ export default defineConfig({
471
+ plugins: [
472
+ react({
473
+ // Fast Refresh options
474
+ fastRefresh: true,
475
+ // Babel options
476
+ babel: {
477
+ plugins: ['babel-plugin-styled-components'],
478
+ },
479
+ }),
480
+ ],
481
+ });
482
+ ```
483
+
484
+ **React Fast Refresh Rules:**
485
+ - Components must be named functions or arrow functions
486
+ - File should export components (named or default)
487
+ - Avoid exporting both components and non-component values
488
+
489
+ ```javascript
490
+ // Good - Fast Refresh works
491
+ export function App() {
492
+ return <div>Hello</div>;
493
+ }
494
+
495
+ // Bad - Fast Refresh breaks
496
+ export const data = { foo: 'bar' };
497
+ export function App() {
498
+ return <div>Hello</div>;
499
+ }
500
+ ```
501
+
502
+ ### Vue with Vite
503
+
504
+ **Plugin Configuration:**
505
+ ```javascript
506
+ // vite.config.js
507
+ import { defineConfig } from 'vite';
508
+ import vue from '@vitejs/plugin-vue';
509
+
510
+ export default defineConfig({
511
+ plugins: [
512
+ vue({
513
+ // Template compilation options
514
+ template: {
515
+ compilerOptions: {
516
+ isCustomElement: (tag) => tag.startsWith('custom-'),
517
+ },
518
+ },
519
+ }),
520
+ ],
521
+ });
522
+ ```
523
+
524
+ **Vue SFC HMR:**
525
+ - Template changes → HMR update
526
+ - Script changes → Full reload (preserves component state when possible)
527
+ - Style changes → HMR update
528
+
529
+ ### Svelte with Vite
530
+
531
+ **Plugin Configuration:**
532
+ ```javascript
533
+ // vite.config.js
534
+ import { defineConfig } from 'vite';
535
+ import { svelte } from '@sveltejs/vite-plugin-svelte';
536
+
537
+ export default defineConfig({
538
+ plugins: [
539
+ svelte({
540
+ hot: true, // Enable HMR
541
+ compilerOptions: {
542
+ dev: true,
543
+ },
544
+ }),
545
+ ],
546
+ });
547
+ ```
548
+
549
+ ## Common Problems & Solutions
550
+
551
+ ### Problem 1: HMR Not Working
552
+
553
+ **Symptoms:**
554
+ - Code changes don't update in browser
555
+ - Need manual refresh after every change
556
+ - Console shows "WebSocket connection failed"
557
+
558
+ **Root Cause:**
559
+ WebSocket connection broken, PM2 interference, Docker networking, or reverse proxy misconfiguration.
560
+
561
+ **Solution:**
562
+
563
+ **Step 1: Verify Direct Dev Server**
564
+ ```bash
565
+ # Stop PM2 if running (PM2 breaks HMR)
566
+ pm2 stop all
567
+
568
+ # Run dev server directly
569
+ npm run dev
570
+ ```
571
+
572
+ **Step 2: Check WebSocket Connection**
573
+
574
+ Open browser console and look for:
575
+ ```
576
+ [vite] connected.
577
+ ```
578
+
579
+ If not connected, check HMR config:
580
+ ```javascript
581
+ // vite.config.js
582
+ export default defineConfig({
583
+ server: {
584
+ hmr: {
585
+ protocol: 'ws',
586
+ host: 'localhost',
587
+ },
588
+ },
589
+ });
590
+ ```
591
+
592
+ **Step 3: Docker HMR Configuration**
593
+
594
+ For Docker, expose HMR to host:
595
+ ```javascript
596
+ // vite.config.js
597
+ export default defineConfig({
598
+ server: {
599
+ host: '0.0.0.0',
600
+ port: 5173,
601
+ hmr: {
602
+ clientPort: 5173,
603
+ },
604
+ watch: {
605
+ usePolling: true, // If file changes not detected
606
+ },
607
+ },
608
+ });
609
+ ```
610
+
611
+ **Step 4: Clear Cache and Restart**
612
+ ```bash
613
+ rm -rf node_modules/.vite
614
+ npm run dev
615
+ ```
616
+
617
+ **Step 5: Check Firewall/Network**
618
+ ```bash
619
+ # Ensure port is accessible
620
+ netstat -an | grep 5173
621
+ ```
622
+
623
+ ### Problem 2: Slow Cold Start
624
+
625
+ **Symptoms:**
626
+ - Initial server startup takes 10+ seconds
627
+ - "Optimizing dependencies" runs every time
628
+ - High CPU usage during startup
629
+
630
+ **Root Cause:**
631
+ Unoptimized dependencies, missing pre-bundling configuration, or large project with many files.
632
+
633
+ **Solution:**
634
+
635
+ **Step 1: Pre-bundle Heavy Dependencies**
636
+ ```javascript
637
+ // vite.config.js
638
+ export default defineConfig({
639
+ optimizeDeps: {
640
+ include: [
641
+ 'react',
642
+ 'react-dom',
643
+ 'react-router-dom',
644
+ '@mui/material',
645
+ 'lodash-es',
646
+ ],
647
+ },
648
+ });
649
+ ```
650
+
651
+ **Step 2: Use Dependency Caching**
652
+
653
+ Vite caches pre-bundled dependencies. If cache is rebuilt frequently:
654
+ ```javascript
655
+ // vite.config.js
656
+ export default defineConfig({
657
+ optimizeDeps: {
658
+ force: false, // Don't force rebuild
659
+ },
660
+ cacheDir: 'node_modules/.vite', // Explicit cache location
661
+ });
662
+ ```
663
+
664
+ **Step 3: Optimize Imports**
665
+
666
+ Use direct imports for tree shaking:
667
+ ```javascript
668
+ // Slow - imports entire library
669
+ import { Button } from '@mui/material';
670
+
671
+ // Fast - direct import
672
+ import Button from '@mui/material/Button';
673
+ ```
674
+
675
+ **Step 4: Reduce Watched Files**
676
+
677
+ Exclude unnecessary directories:
678
+ ```javascript
679
+ // vite.config.js
680
+ export default defineConfig({
681
+ server: {
682
+ watch: {
683
+ ignored: ['**/node_modules/**', '**/dist/**', '**/.git/**'],
684
+ },
685
+ },
686
+ });
687
+ ```
688
+
689
+ **Step 5: Use SSD for node_modules**
690
+
691
+ If project is on network drive or slow disk, move node_modules:
692
+ ```bash
693
+ # Use local disk for node_modules
694
+ npm config set cache /path/to/fast/disk/.npm
695
+ ```
696
+
697
+ ### Problem 3: Port Already in Use
698
+
699
+ **Symptoms:**
700
+ ```
701
+ Port 5173 is in use, trying another one...
702
+ # or
703
+ Error: listen EADDRINUSE: address already in use :::5173
704
+ ```
705
+
706
+ **Root Cause:**
707
+ Previous Vite instance, another dev server, or zombie process using the port.
708
+
709
+ **Solution:**
710
+
711
+ **Option A: Kill Process**
712
+ ```bash
713
+ # macOS/Linux
714
+ lsof -ti:5173 | xargs kill -9
715
+
716
+ # Windows
717
+ netstat -ano | findstr :5173
718
+ taskkill /PID <PID> /F
719
+ ```
720
+
721
+ **Option B: Use Different Port**
722
+ ```bash
723
+ npm run dev -- --port 3001
724
+ ```
725
+
726
+ **Option C: Auto-increment Port**
727
+
728
+ Vite automatically tries next port if default is taken:
729
+ ```javascript
730
+ // vite.config.js
731
+ export default defineConfig({
732
+ server: {
733
+ port: 5173,
734
+ strictPort: false, // Try next available port
735
+ },
736
+ });
737
+ ```
738
+
739
+ **Option D: Cleanup Script**
740
+ ```json
741
+ {
742
+ "scripts": {
743
+ "predev": "kill-port 5173 || true",
744
+ "dev": "vite"
745
+ }
746
+ }
747
+ ```
748
+
749
+ ### Problem 4: PM2 Breaks HMR
750
+
751
+ **Symptoms:**
752
+ - HMR works without PM2 but fails with PM2
753
+ - WebSocket connections drop
754
+ - Page doesn't update on file changes
755
+
756
+ **Root Cause:**
757
+ PM2's process management interferes with Vite's HMR WebSocket connections.
758
+
759
+ **Solution:**
760
+
761
+ **NEVER use PM2 for Vite development server.**
762
+
763
+ **Wrong:**
764
+ ```bash
765
+ # Don't do this
766
+ pm2 start npm --name "vite-dev" -- run dev
767
+ ```
768
+
769
+ **Correct:**
770
+ ```bash
771
+ # Run Vite directly
772
+ npm run dev
773
+ ```
774
+
775
+ **Why PM2 Breaks Vite HMR:**
776
+ - PM2 wraps the process, breaking WebSocket connections
777
+ - Process restarts disconnect HMR clients
778
+ - Watch mode conflicts with Vite's file watching
779
+
780
+ **For Production:**
781
+
782
+ Build static files, serve with any static server:
783
+ ```bash
784
+ # Build
785
+ npm run build
786
+
787
+ # Serve with simple HTTP server (not PM2)
788
+ npx serve -s dist -p 5173
789
+
790
+ # Or use nginx, Apache, or CDN
791
+ ```
792
+
793
+ **PM2 is for backend servers, not frontend build tools.**
794
+
795
+ ### Problem 5: WSL2 File Watching Issues
796
+
797
+ **Symptoms:**
798
+ - Changes in Windows files not detected by Vite in WSL2
799
+ - Need to manually restart server
800
+ - High CPU usage with polling
801
+
802
+ **Root Cause:**
803
+ File system events don't cross Windows-Linux boundary efficiently.
804
+
805
+ **Solution:**
806
+
807
+ **Option 1: Move Project to WSL2 Filesystem (Best)**
808
+ ```bash
809
+ # Move to WSL2 native filesystem
810
+ cd ~
811
+ mkdir projects
812
+ cd projects
813
+ git clone <repo>
814
+ npm install
815
+ npm run dev
816
+ ```
817
+
818
+ **Option 2: Enable Polling (Fallback)**
819
+ ```javascript
820
+ // vite.config.js
821
+ export default defineConfig({
822
+ server: {
823
+ watch: {
824
+ usePolling: true,
825
+ interval: 1000,
826
+ },
827
+ },
828
+ });
829
+ ```
830
+
831
+ **Option 3: Environment Variable**
832
+ ```bash
833
+ CHOKIDAR_USEPOLLING=true npm run dev
834
+ ```
835
+
836
+ **Performance Comparison:**
837
+ - Native WSL2 filesystem: Fast, low CPU
838
+ - Polling from /mnt/c/: Slow, high CPU
839
+ - Native file watching from /mnt/c/: Doesn't work
840
+
841
+ **Recommendation:** Always develop in WSL2 native filesystem (`~/projects`), not in `/mnt/c/`.
842
+
843
+ ## Anti-Patterns
844
+
845
+ ### What NOT to Do
846
+
847
+ **1. Never Use PM2 for Vite Dev Server**
848
+ ```bash
849
+ # WRONG - Breaks HMR completely
850
+ pm2 start npm --name "vite-dev" -- run dev
851
+ ```
852
+
853
+ Why: PM2 breaks WebSocket connections required for HMR.
854
+
855
+ **2. Don't Use Vite Dev Server in Production**
856
+ ```bash
857
+ # WRONG for production
858
+ npm run dev
859
+ ```
860
+
861
+ Correct:
862
+ ```bash
863
+ npm run build
864
+ npx serve -s dist
865
+ ```
866
+
867
+ **3. Don't Ignore Pre-bundling Optimization**
868
+ ```javascript
869
+ // WRONG - misses optimization opportunity
870
+ // No optimizeDeps configuration
871
+ ```
872
+
873
+ Correct:
874
+ ```javascript
875
+ // Pre-bundle heavy dependencies
876
+ export default defineConfig({
877
+ optimizeDeps: {
878
+ include: ['react', 'react-dom', 'lodash-es'],
879
+ },
880
+ });
881
+ ```
882
+
883
+ **4. Don't Use Polling in Native Filesystem**
884
+ ```javascript
885
+ // WRONG - unnecessary CPU usage
886
+ export default defineConfig({
887
+ server: {
888
+ watch: {
889
+ usePolling: true, // Only needed for WSL/Docker
890
+ },
891
+ },
892
+ });
893
+ ```
894
+
895
+ Use polling only in WSL2 or Docker where native watching doesn't work.
896
+
897
+ **5. Don't Mix Default and Named Exports**
898
+ ```javascript
899
+ // WRONG - confuses HMR
900
+ export default function App() {}
901
+ export const utils = {};
902
+ ```
903
+
904
+ Stick to named exports for components:
905
+ ```javascript
906
+ // Better
907
+ export function App() {}
908
+ ```
909
+
910
+ **6. Don't Import Entire Libraries**
911
+ ```javascript
912
+ // WRONG - imports everything
913
+ import _ from 'lodash';
914
+ import * as MaterialUI from '@mui/material';
915
+ ```
916
+
917
+ Use tree-shakeable imports:
918
+ ```javascript
919
+ // Correct
920
+ import { debounce } from 'lodash-es';
921
+ import Button from '@mui/material/Button';
922
+ ```
923
+
924
+ **7. Don't Expose Secrets via VITE_ Prefix**
925
+ ```bash
926
+ # WRONG - exposed to client
927
+ VITE_API_SECRET=super-secret-key
928
+ ```
929
+
930
+ VITE_ prefixed variables are in client bundle. Use backend for secrets.
931
+
932
+ ## Quick Reference
933
+
934
+ ### Commands
935
+
936
+ ```bash
937
+ # Development
938
+ npm run dev # Start dev server
939
+ npm run dev -- --port 3001 # Custom port
940
+ npm run dev -- --host 0.0.0.0 # Listen on all interfaces
941
+ npm run dev -- --open # Auto-open browser
942
+ npm run dev -- --force # Force dependency pre-bundling
943
+
944
+ # Production
945
+ npm run build # Build for production
946
+ npm run preview # Preview production build
947
+ npx serve -s dist # Serve built files
948
+
949
+ # Maintenance
950
+ rm -rf node_modules/.vite # Clear Vite cache
951
+ rm -rf dist # Clear build output
952
+ lsof -ti:5173 | xargs kill -9 # Kill process on port
953
+
954
+ # WSL2
955
+ CHOKIDAR_USEPOLLING=true npm run dev # Enable polling
956
+ ```
957
+
958
+ ### Configuration Templates
959
+
960
+ **Minimal vite.config.js:**
961
+ ```javascript
962
+ import { defineConfig } from 'vite';
963
+ import react from '@vitejs/plugin-react';
964
+
965
+ export default defineConfig({
966
+ plugins: [react()],
967
+ server: {
968
+ port: 5173,
969
+ open: true,
970
+ },
971
+ });
972
+ ```
973
+
974
+ **Optimized vite.config.js:**
975
+ ```javascript
976
+ import { defineConfig } from 'vite';
977
+ import react from '@vitejs/plugin-react';
978
+
979
+ export default defineConfig({
980
+ plugins: [react()],
981
+ server: {
982
+ port: 5173,
983
+ host: true,
984
+ open: true,
985
+ hmr: {
986
+ overlay: true,
987
+ },
988
+ proxy: {
989
+ '/api': {
990
+ target: 'http://localhost:4000',
991
+ changeOrigin: true,
992
+ },
993
+ },
994
+ },
995
+ optimizeDeps: {
996
+ include: ['react', 'react-dom', 'react-router-dom'],
997
+ },
998
+ build: {
999
+ sourcemap: true,
1000
+ rollupOptions: {
1001
+ output: {
1002
+ manualChunks: {
1003
+ vendor: ['react', 'react-dom'],
1004
+ },
1005
+ },
1006
+ },
1007
+ },
1008
+ });
1009
+ ```
1010
+
1011
+ **WSL2/Docker vite.config.js:**
1012
+ ```javascript
1013
+ export default defineConfig({
1014
+ plugins: [react()],
1015
+ server: {
1016
+ host: '0.0.0.0',
1017
+ port: 5173,
1018
+ hmr: {
1019
+ clientPort: 5173,
1020
+ },
1021
+ watch: {
1022
+ usePolling: true,
1023
+ interval: 1000,
1024
+ },
1025
+ },
1026
+ });
1027
+ ```
1028
+
1029
+ **Full Stack with API Proxy:**
1030
+ ```javascript
1031
+ export default defineConfig({
1032
+ plugins: [react()],
1033
+ server: {
1034
+ port: 3000,
1035
+ proxy: {
1036
+ '/api': {
1037
+ target: 'http://localhost:4000',
1038
+ changeOrigin: true,
1039
+ rewrite: (path) => path.replace(/^\/api/, ''),
1040
+ },
1041
+ '/ws': {
1042
+ target: 'ws://localhost:4000',
1043
+ ws: true,
1044
+ },
1045
+ },
1046
+ },
1047
+ });
1048
+ ```
1049
+
1050
+ ## Related Skills
1051
+
1052
+ - **nextjs-local-dev** - For Next.js with similar HMR patterns
1053
+ - **docker-containerization** - For containerized Vite applications
1054
+ - **systematic-debugging** - For complex debugging scenarios
1055
+ - **express-local-dev** - For full-stack applications with Express backend
1056
+
1057
+ ---
1058
+
1059
+ **Vite Version Compatibility:** This skill covers Vite 4.0+ and Vite 5.0+. Most patterns are stable across versions.
1060
+
1061
+ **Last Updated:** 2024 - Reflects current Vite best practices and HMR optimization techniques.