vibes-plug 1.0.0

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.
Files changed (141) hide show
  1. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  2. package/BLUEPRINT.md +125 -0
  3. package/CHANGELOG.md +195 -0
  4. package/CONTRIBUTING.md +199 -0
  5. package/LICENSE +21 -0
  6. package/README.md +263 -0
  7. package/SECURITY.md +21 -0
  8. package/banner.png +0 -0
  9. package/package.json +25 -0
  10. package/plugin.json +8 -0
  11. package/scripts/update_skills.js +75 -0
  12. package/skills/ai-llm-integration-expert/SKILL.md +162 -0
  13. package/skills/api-design-expert/SKILL.md +310 -0
  14. package/skills/app-analyzer-optimizer/SKILL.md +189 -0
  15. package/skills/asisten_ramah/SKILL.md +41 -0
  16. package/skills/authentication-identity-expert/SKILL.md +45 -0
  17. package/skills/auto-doc-updater/SKILL.md +204 -0
  18. package/skills/bootstrap-to-modern/SKILL.md +87 -0
  19. package/skills/brainstorming/SKILL.md +353 -0
  20. package/skills/bun-runtime-expert/SKILL.md +211 -0
  21. package/skills/ci-cd-devops-architect/SKILL.md +45 -0
  22. package/skills/cloud-hosting-expert/SKILL.md +244 -0
  23. package/skills/coderabbit/SKILL.md +192 -0
  24. package/skills/data-telemetry-expert/SKILL.md +213 -0
  25. package/skills/database-orm-expert/SKILL.md +294 -0
  26. package/skills/design-system-architect/SKILL.md +243 -0
  27. package/skills/e2e-testing-expert/SKILL.md +315 -0
  28. package/skills/event-driven-architect/SKILL.md +81 -0
  29. package/skills/firebase-security-expert/SKILL.md +195 -0
  30. package/skills/fullstack-expert/SKILL.md +202 -0
  31. package/skills/fullstack-expert/references/api_design_guide.md +466 -0
  32. package/skills/fullstack-expert/references/devops_infrastructure.md +477 -0
  33. package/skills/fullstack-expert/references/multi_language_backend.md +528 -0
  34. package/skills/fullstack-expert/references/system_design_patterns.md +358 -0
  35. package/skills/fullstack-expert/scripts/api_contract_validator.py +253 -0
  36. package/skills/fullstack-expert/scripts/architecture_analyzer.py +326 -0
  37. package/skills/gemini-agent-booster/SKILL.md +135 -0
  38. package/skills/global-a11y-i18n-expert/SKILL.md +81 -0
  39. package/skills/go-programming-expert/SKILL.md +295 -0
  40. package/skills/hig/SKILL.md +188 -0
  41. package/skills/js-backend-expert/SKILL.md +192 -0
  42. package/skills/mcp-server-architect/SKILL.md +194 -0
  43. package/skills/mobile-expo-expert/SKILL.md +186 -0
  44. package/skills/monday-design-aesthetic/SKILL.md +67 -0
  45. package/skills/monorepo-architect/SKILL.md +227 -0
  46. package/skills/mpa-orchestrator/SKILL.md +101 -0
  47. package/skills/multi-agent-orchestration/SKILL.md +234 -0
  48. package/skills/multiple-entry-points/SKILL.md +55 -0
  49. package/skills/mvc-expert/SKILL.md +231 -0
  50. package/skills/payment-gateway-expert/SKILL.md +45 -0
  51. package/skills/performance-web-vitals/SKILL.md +332 -0
  52. package/skills/prd-architect/SKILL.md +191 -0
  53. package/skills/production-ready-hardener/SKILL.md +469 -0
  54. package/skills/production-ready-hardener/references/performance_optimization.md +441 -0
  55. package/skills/production-ready-hardener/references/production_checklist.md +161 -0
  56. package/skills/production-ready-hardener/references/security_hardening_guide.md +379 -0
  57. package/skills/production-ready-hardener/scripts/production_readiness_scanner.py +875 -0
  58. package/skills/python-programming-expert/SKILL.md +271 -0
  59. package/skills/realtime-collaboration-expert/SKILL.md +45 -0
  60. package/skills/rust-programming-expert/SKILL.md +235 -0
  61. package/skills/saas-billing/SKILL.md +377 -0
  62. package/skills/saas-multi-tenant/SKILL.md +237 -0
  63. package/skills/saas-mvp-launcher/SKILL.md +231 -0
  64. package/skills/saas-transformer/SKILL.md +446 -0
  65. package/skills/saas-transformer/references/billing_integration_guide.md +401 -0
  66. package/skills/saas-transformer/references/feature_gating_patterns.md +137 -0
  67. package/skills/saas-transformer/references/saas_transformation_checklist.md +121 -0
  68. package/skills/saas-transformer/scripts/saas_transformation_scanner.py +254 -0
  69. package/skills/scalability-clean-code/SKILL.md +229 -0
  70. package/skills/secure-fuzz-testing/SKILL.md +201 -0
  71. package/skills/senior-frontend/SKILL.md +161 -0
  72. package/skills/senior-frontend/references/frontend_best_practices.md +806 -0
  73. package/skills/senior-frontend/references/nextjs_optimization_guide.md +724 -0
  74. package/skills/senior-frontend/references/react_patterns.md +746 -0
  75. package/skills/senior-frontend/scripts/bundle_analyzer.py +407 -0
  76. package/skills/senior-frontend/scripts/component_generator.py +329 -0
  77. package/skills/senior-frontend/scripts/frontend_scaffolder.py +1005 -0
  78. package/skills/senior-fullstack/SKILL.md +167 -0
  79. package/skills/senior-fullstack/references/architecture_patterns.md +160 -0
  80. package/skills/senior-fullstack/references/development_workflows.md +222 -0
  81. package/skills/senior-fullstack/references/tech_stack_guide.md +190 -0
  82. package/skills/senior-fullstack/scripts/code_quality_analyzer.py +114 -0
  83. package/skills/senior-fullstack/scripts/fullstack_scaffolder.py +114 -0
  84. package/skills/senior-fullstack/scripts/project_scaffolder.py +114 -0
  85. package/skills/seo/SKILL.md +225 -0
  86. package/skills/seo/references/cwv-thresholds.md +108 -0
  87. package/skills/seo/references/eeat-framework.md +214 -0
  88. package/skills/seo/references/quality-gates.md +155 -0
  89. package/skills/seo/references/schema-types.md +118 -0
  90. package/skills/seo-aeo-landing-page-writer/SKILL.md +97 -0
  91. package/skills/seo-geo/SKILL.md +188 -0
  92. package/skills/session-handoff-resume/SKILL.md +158 -0
  93. package/skills/skill_baru/SKILL.md +147 -0
  94. package/skills/spa-orchestrator/SKILL.md +288 -0
  95. package/skills/state-management-expert/SKILL.md +272 -0
  96. package/skills/supabase-migration/SKILL.md +45 -0
  97. package/skills/supabase-security-expert/SKILL.md +243 -0
  98. package/skills/tailwind-expert/SKILL.md +188 -0
  99. package/skills/tanstack-query-expert/SKILL.md +199 -0
  100. package/skills/tauri-expert/SKILL.md +97 -0
  101. package/skills/token-saver/SKILL.md +111 -0
  102. package/skills/typescript-expert/SKILL.md +279 -0
  103. package/skills/ui-components-expert/SKILL.md +63 -0
  104. package/skills/ui-ux-pro-max/SKILL.md +201 -0
  105. package/skills/ui-ux-pro-max/data/charts.csv +26 -0
  106. package/skills/ui-ux-pro-max/data/colors.csv +97 -0
  107. package/skills/ui-ux-pro-max/data/icons.csv +101 -0
  108. package/skills/ui-ux-pro-max/data/landing.csv +31 -0
  109. package/skills/ui-ux-pro-max/data/products.csv +97 -0
  110. package/skills/ui-ux-pro-max/data/prompts.csv +24 -0
  111. package/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
  112. package/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  113. package/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  114. package/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  115. package/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  116. package/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  117. package/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  118. package/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
  119. package/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  120. package/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  121. package/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  122. package/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  123. package/skills/ui-ux-pro-max/data/styles.csv +59 -0
  124. package/skills/ui-ux-pro-max/data/typography.csv +58 -0
  125. package/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  126. package/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  127. package/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
  128. package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-310.pyc +0 -0
  129. package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-312.pyc +0 -0
  130. package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-310.pyc +0 -0
  131. package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-312.pyc +0 -0
  132. package/skills/ui-ux-pro-max/scripts/core.py +257 -0
  133. package/skills/ui-ux-pro-max/scripts/design_system.py +493 -0
  134. package/skills/ui-ux-pro-max/scripts/search.py +81 -0
  135. package/skills/ui_ux_expert/SKILL.md +114 -0
  136. package/skills/vibe-code-gardener/SKILL.md +173 -0
  137. package/skills/web-scraper/SKILL.md +205 -0
  138. package/skills/web-scraper/references/data-transforms.md +397 -0
  139. package/skills/web-scraper/references/extraction-patterns.md +475 -0
  140. package/skills/web-scraper/references/output-templates.md +481 -0
  141. package/skills/zero-to-prod-orchestrator/SKILL.md +180 -0
@@ -0,0 +1,724 @@
1
+ # Next.js Optimization Guide
2
+
3
+ Performance optimization techniques for Next.js 15 applications with React Server Components, Turbopack, and modern caching strategies.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ - [Rendering Strategies](#rendering-strategies)
10
+ - [Image Optimization](#image-optimization)
11
+ - [Code Splitting](#code-splitting)
12
+ - [Data Fetching](#data-fetching)
13
+ - [Caching Strategies](#caching-strategies)
14
+ - [Bundle Optimization](#bundle-optimization)
15
+ - [Core Web Vitals](#core-web-vitals)
16
+
17
+ ---
18
+
19
+ ## Rendering Strategies
20
+
21
+ ### Server Components (Default)
22
+
23
+ Server Components render on the server and send HTML to the client. Use for data-heavy, non-interactive content.
24
+
25
+ ```tsx
26
+ // app/products/page.tsx - Server Component (default)
27
+ async function ProductsPage() {
28
+ // This runs on the server - no client bundle impact
29
+ const products = await db.products.findMany();
30
+
31
+ return (
32
+ <div className="grid grid-cols-3 gap-4">
33
+ {products.map(product => (
34
+ <ProductCard key={product.id} product={product} />
35
+ ))}
36
+ </div>
37
+ );
38
+ }
39
+ ```
40
+
41
+ ### Client Components
42
+
43
+ Use `'use client'` only when you need:
44
+ - Event handlers (onClick, onChange)
45
+ - State (useState, useReducer)
46
+ - Effects (useEffect)
47
+ - Browser APIs (window, document)
48
+
49
+ ```tsx
50
+ 'use client';
51
+
52
+ import { useState } from 'react';
53
+
54
+ function AddToCartButton({ productId }: { productId: string }) {
55
+ const [isAdding, setIsAdding] = useState(false);
56
+
57
+ async function handleClick() {
58
+ setIsAdding(true);
59
+ await addToCart(productId);
60
+ setIsAdding(false);
61
+ }
62
+
63
+ return (
64
+ <button onClick={handleClick} disabled={isAdding}>
65
+ {isAdding ? 'Adding...' : 'Add to Cart'}
66
+ </button>
67
+ );
68
+ }
69
+ ```
70
+
71
+ ### Mixing Server and Client Components
72
+
73
+ ```tsx
74
+ // app/products/[id]/page.tsx - Server Component
75
+ async function ProductPage({ params }: { params: { id: string } }) {
76
+ const product = await getProduct(params.id);
77
+
78
+ return (
79
+ <div>
80
+ {/* Server-rendered content */}
81
+ <h1>{product.name}</h1>
82
+ <p>{product.description}</p>
83
+
84
+ {/* Client component for interactivity */}
85
+ <AddToCartButton productId={product.id} />
86
+
87
+ {/* Server component for reviews */}
88
+ <ProductReviews productId={product.id} />
89
+ </div>
90
+ );
91
+ }
92
+ ```
93
+
94
+ ### Static vs Dynamic Rendering
95
+
96
+ ```tsx
97
+ // Force static generation at build time
98
+ export const dynamic = 'force-static';
99
+
100
+ // Force dynamic rendering at request time
101
+ export const dynamic = 'force-dynamic';
102
+
103
+ // Revalidate every 60 seconds (ISR)
104
+ export const revalidate = 60;
105
+
106
+ // Revalidate on-demand
107
+ import { revalidatePath, revalidateTag } from 'next/cache';
108
+
109
+ async function updateProduct(id: string, data: ProductData) {
110
+ await db.products.update({ where: { id }, data });
111
+
112
+ // Revalidate specific path
113
+ revalidatePath(`/products/${id}`);
114
+
115
+ // Or revalidate by tag
116
+ revalidateTag('products');
117
+ }
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Image Optimization
123
+
124
+ ### Next.js Image Component
125
+
126
+ ```tsx
127
+ import Image from 'next/image';
128
+
129
+ // Basic optimized image
130
+ <Image
131
+ src="/hero.jpg"
132
+ alt="Hero image"
133
+ width={1200}
134
+ height={600}
135
+ priority // Load immediately for LCP
136
+ />
137
+
138
+ // Responsive image
139
+ <Image
140
+ src="/product.jpg"
141
+ alt="Product"
142
+ fill
143
+ sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
144
+ className="object-cover"
145
+ />
146
+
147
+ // With placeholder blur
148
+ import productImage from '@/public/product.jpg';
149
+
150
+ <Image
151
+ src={productImage}
152
+ alt="Product"
153
+ placeholder="blur" // Uses imported image data
154
+ />
155
+ ```
156
+
157
+ ### Remote Images Configuration
158
+
159
+ ```js
160
+ // next.config.js
161
+ module.exports = {
162
+ images: {
163
+ remotePatterns: [
164
+ {
165
+ protocol: 'https',
166
+ hostname: 'cdn.example.com',
167
+ pathname: '/images/**',
168
+ },
169
+ {
170
+ protocol: 'https',
171
+ hostname: '*.cloudinary.com',
172
+ },
173
+ ],
174
+ // Image formats (webp is default)
175
+ formats: ['image/avif', 'image/webp'],
176
+ // Device sizes for srcset
177
+ deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
178
+ // Image sizes for srcset
179
+ imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
180
+ },
181
+ };
182
+ ```
183
+
184
+ ### Lazy Loading Patterns
185
+
186
+ ```tsx
187
+ // Images below the fold - lazy load (default)
188
+ <Image
189
+ src="/gallery/photo1.jpg"
190
+ alt="Gallery photo"
191
+ width={400}
192
+ height={300}
193
+ loading="lazy" // Default behavior
194
+ />
195
+
196
+ // Above the fold - load immediately
197
+ <Image
198
+ src="/hero.jpg"
199
+ alt="Hero"
200
+ width={1200}
201
+ height={600}
202
+ priority
203
+ loading="eager"
204
+ />
205
+ ```
206
+
207
+ ---
208
+
209
+ ## Code Splitting
210
+
211
+ ### Dynamic Imports
212
+
213
+ ```tsx
214
+ import dynamic from 'next/dynamic';
215
+
216
+ // Basic dynamic import
217
+ const HeavyChart = dynamic(() => import('@/components/HeavyChart'), {
218
+ loading: () => <ChartSkeleton />,
219
+ });
220
+
221
+ // Disable SSR for client-only components
222
+ const MapComponent = dynamic(() => import('@/components/Map'), {
223
+ ssr: false,
224
+ loading: () => <div className="h-[400px] bg-gray-100" />,
225
+ });
226
+
227
+ // Named exports
228
+ const Modal = dynamic(() =>
229
+ import('@/components/ui').then(mod => mod.Modal)
230
+ );
231
+
232
+ // With suspense
233
+ const DashboardCharts = dynamic(() => import('@/components/DashboardCharts'), {
234
+ loading: () => <Suspense fallback={<ChartsSkeleton />} />,
235
+ });
236
+ ```
237
+
238
+ ### Route-Based Splitting
239
+
240
+ ```tsx
241
+ // app/dashboard/analytics/page.tsx
242
+ // This page only loads when /dashboard/analytics is visited
243
+ import { Suspense } from 'react';
244
+ import AnalyticsCharts from './AnalyticsCharts';
245
+
246
+ export default function AnalyticsPage() {
247
+ return (
248
+ <Suspense fallback={<AnalyticsSkeleton />}>
249
+ <AnalyticsCharts />
250
+ </Suspense>
251
+ );
252
+ }
253
+ ```
254
+
255
+ ### Parallel Routes for Code Splitting
256
+
257
+ ```
258
+ app/
259
+ ├── dashboard/
260
+ │ ├── @analytics/
261
+ │ │ └── page.tsx # Loaded in parallel
262
+ │ ├── @metrics/
263
+ │ │ └── page.tsx # Loaded in parallel
264
+ │ ├── layout.tsx
265
+ │ └── page.tsx
266
+ ```
267
+
268
+ ```tsx
269
+ // app/dashboard/layout.tsx
270
+ export default function DashboardLayout({
271
+ children,
272
+ analytics,
273
+ metrics,
274
+ }: {
275
+ children: React.ReactNode;
276
+ analytics: React.ReactNode;
277
+ metrics: React.ReactNode;
278
+ }) {
279
+ return (
280
+ <div className="grid grid-cols-2 gap-4">
281
+ {children}
282
+ <Suspense fallback={<AnalyticsSkeleton />}>{analytics}</Suspense>
283
+ <Suspense fallback={<MetricsSkeleton />}>{metrics}</Suspense>
284
+ </div>
285
+ );
286
+ }
287
+ ```
288
+
289
+ ---
290
+
291
+ ## Data Fetching
292
+
293
+ ### Server-Side Data Fetching
294
+
295
+ ```tsx
296
+ // Parallel data fetching
297
+ async function Dashboard() {
298
+ // Start both requests simultaneously
299
+ const [user, stats, notifications] = await Promise.all([
300
+ getUser(),
301
+ getStats(),
302
+ getNotifications(),
303
+ ]);
304
+
305
+ return (
306
+ <div>
307
+ <UserHeader user={user} />
308
+ <StatsPanel stats={stats} />
309
+ <NotificationList notifications={notifications} />
310
+ </div>
311
+ );
312
+ }
313
+ ```
314
+
315
+ ### Streaming with Suspense
316
+
317
+ ```tsx
318
+ import { Suspense } from 'react';
319
+
320
+ async function ProductPage({ params }: { params: { id: string } }) {
321
+ const product = await getProduct(params.id);
322
+
323
+ return (
324
+ <div>
325
+ {/* Immediate content */}
326
+ <h1>{product.name}</h1>
327
+ <p>{product.description}</p>
328
+
329
+ {/* Stream reviews - don't block page */}
330
+ <Suspense fallback={<ReviewsSkeleton />}>
331
+ <Reviews productId={params.id} />
332
+ </Suspense>
333
+
334
+ {/* Stream recommendations */}
335
+ <Suspense fallback={<RecommendationsSkeleton />}>
336
+ <Recommendations productId={params.id} />
337
+ </Suspense>
338
+ </div>
339
+ );
340
+ }
341
+
342
+ // Slow data component
343
+ async function Reviews({ productId }: { productId: string }) {
344
+ const reviews = await getReviews(productId); // Slow query
345
+ return <ReviewList reviews={reviews} />;
346
+ }
347
+ ```
348
+
349
+ ### Request Memoization
350
+
351
+ ```tsx
352
+ // Next.js automatically dedupes identical requests
353
+ async function Layout({ children }) {
354
+ const user = await getUser(); // Request 1
355
+ return <div>{children}</div>;
356
+ }
357
+
358
+ async function Header() {
359
+ const user = await getUser(); // Same request - cached!
360
+ return <div>Hello, {user.name}</div>;
361
+ }
362
+
363
+ // Both components call getUser() but only one request is made
364
+ ```
365
+
366
+ ---
367
+
368
+ ## Caching Strategies
369
+
370
+ ### Fetch Cache Options
371
+
372
+ ```tsx
373
+ // Cache indefinitely (default for static)
374
+ fetch('https://api.example.com/data');
375
+
376
+ // No cache - always fresh
377
+ fetch('https://api.example.com/data', { cache: 'no-store' });
378
+
379
+ // Revalidate after time
380
+ fetch('https://api.example.com/data', {
381
+ next: { revalidate: 3600 } // 1 hour
382
+ });
383
+
384
+ // Tag-based revalidation
385
+ fetch('https://api.example.com/products', {
386
+ next: { tags: ['products'] }
387
+ });
388
+
389
+ // Later, revalidate by tag
390
+ import { revalidateTag } from 'next/cache';
391
+ revalidateTag('products');
392
+ ```
393
+
394
+ ### Route Segment Config
395
+
396
+ ```tsx
397
+ // app/products/page.tsx
398
+
399
+ // Revalidate every hour
400
+ export const revalidate = 3600;
401
+
402
+ // Or force dynamic
403
+ export const dynamic = 'force-dynamic';
404
+
405
+ // Generate static params at build
406
+ export async function generateStaticParams() {
407
+ const products = await getProducts();
408
+ return products.map(p => ({ id: p.id }));
409
+ }
410
+ ```
411
+
412
+ ### unstable_cache for Custom Caching
413
+
414
+ ```tsx
415
+ import { unstable_cache } from 'next/cache';
416
+
417
+ const getCachedUser = unstable_cache(
418
+ async (userId: string) => {
419
+ const user = await db.users.findUnique({ where: { id: userId } });
420
+ return user;
421
+ },
422
+ ['user-cache'],
423
+ {
424
+ revalidate: 3600, // 1 hour
425
+ tags: ['users'],
426
+ }
427
+ );
428
+
429
+ // Usage
430
+ const user = await getCachedUser(userId);
431
+ ```
432
+
433
+ ---
434
+
435
+ ## Bundle Optimization
436
+
437
+ ### Analyze Bundle Size
438
+
439
+ ```bash
440
+ # Install analyzer
441
+ npm install @next/bundle-analyzer
442
+
443
+ # Update next.config.js
444
+ const withBundleAnalyzer = require('@next/bundle-analyzer')({
445
+ enabled: process.env.ANALYZE === 'true',
446
+ });
447
+
448
+ module.exports = withBundleAnalyzer({
449
+ // config
450
+ });
451
+
452
+ # Run analysis
453
+ ANALYZE=true npm run build
454
+ ```
455
+
456
+ ### Tree Shaking Imports
457
+
458
+ ```tsx
459
+ // BAD - Imports entire library
460
+ import _ from 'lodash';
461
+ const result = _.debounce(fn, 300);
462
+
463
+ // GOOD - Import only what you need
464
+ import debounce from 'lodash/debounce';
465
+ const result = debounce(fn, 300);
466
+
467
+ // GOOD - Named imports (tree-shakeable)
468
+ import { debounce } from 'lodash-es';
469
+ ```
470
+
471
+ ### Optimize Dependencies
472
+
473
+ ```js
474
+ // next.config.js
475
+ module.exports = {
476
+ // Transpile specific packages
477
+ transpilePackages: ['ui-library', 'shared-utils'],
478
+
479
+ // Optimize package imports
480
+ experimental: {
481
+ optimizePackageImports: ['lucide-react', '@heroicons/react'],
482
+ },
483
+
484
+ // External packages for server
485
+ serverExternalPackages: ['sharp', 'bcrypt'],
486
+ };
487
+ ```
488
+
489
+ ### Font Optimization
490
+
491
+ ```tsx
492
+ // app/layout.tsx
493
+ import { Inter, Roboto_Mono } from 'next/font/google';
494
+
495
+ const inter = Inter({
496
+ subsets: ['latin'],
497
+ display: 'swap',
498
+ variable: '--font-inter',
499
+ });
500
+
501
+ const robotoMono = Roboto_Mono({
502
+ subsets: ['latin'],
503
+ display: 'swap',
504
+ variable: '--font-roboto-mono',
505
+ });
506
+
507
+ export default function RootLayout({ children }) {
508
+ return (
509
+ <html lang="en" className={`${inter.variable} ${robotoMono.variable}`}>
510
+ <body className="font-sans">{children}</body>
511
+ </html>
512
+ );
513
+ }
514
+ ```
515
+
516
+ ---
517
+
518
+ ## Core Web Vitals
519
+
520
+ ### Largest Contentful Paint (LCP)
521
+
522
+ ```tsx
523
+ // Optimize LCP hero image
524
+ import Image from 'next/image';
525
+
526
+ export default function Hero() {
527
+ return (
528
+ <section className="relative h-[600px]">
529
+ <Image
530
+ src="/hero.jpg"
531
+ alt="Hero"
532
+ fill
533
+ priority // Preload for LCP
534
+ sizes="100vw"
535
+ className="object-cover"
536
+ />
537
+ <div className="relative z-10">
538
+ <h1>Welcome</h1>
539
+ </div>
540
+ </section>
541
+ );
542
+ }
543
+
544
+ // Preload critical resources in layout
545
+ export default function RootLayout({ children }) {
546
+ return (
547
+ <html>
548
+ <head>
549
+ <link rel="preload" href="/hero.jpg" as="image" />
550
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
551
+ </head>
552
+ <body>{children}</body>
553
+ </html>
554
+ );
555
+ }
556
+ ```
557
+
558
+ ### Cumulative Layout Shift (CLS)
559
+
560
+ ```tsx
561
+ // Prevent CLS with explicit dimensions
562
+ <Image
563
+ src="/product.jpg"
564
+ alt="Product"
565
+ width={400}
566
+ height={300}
567
+ />
568
+
569
+ // Or use aspect ratio
570
+ <div className="aspect-video relative">
571
+ <Image src="/video-thumb.jpg" alt="Video" fill />
572
+ </div>
573
+
574
+ // Skeleton placeholders
575
+ function ProductCard({ product }: { product?: Product }) {
576
+ if (!product) {
577
+ return (
578
+ <div className="animate-pulse">
579
+ <div className="h-48 bg-gray-200 rounded" />
580
+ <div className="h-4 bg-gray-200 rounded mt-2 w-3/4" />
581
+ <div className="h-4 bg-gray-200 rounded mt-1 w-1/2" />
582
+ </div>
583
+ );
584
+ }
585
+
586
+ return (
587
+ <div>
588
+ <Image src={product.image} alt={product.name} width={300} height={200} />
589
+ <h3>{product.name}</h3>
590
+ <p>{product.price}</p>
591
+ </div>
592
+ );
593
+ }
594
+ ```
595
+
596
+ ### First Input Delay (FID) / Interaction to Next Paint (INP)
597
+
598
+ ```tsx
599
+ // Defer non-critical JavaScript
600
+ import Script from 'next/script';
601
+
602
+ export default function Layout({ children }) {
603
+ return (
604
+ <html>
605
+ <body>
606
+ {children}
607
+
608
+ {/* Load analytics after page is interactive */}
609
+ <Script
610
+ src="https://analytics.example.com/script.js"
611
+ strategy="afterInteractive"
612
+ />
613
+
614
+ {/* Load chat widget when idle */}
615
+ <Script
616
+ src="https://chat.example.com/widget.js"
617
+ strategy="lazyOnload"
618
+ />
619
+ </body>
620
+ </html>
621
+ );
622
+ }
623
+
624
+ // Use web workers for heavy computation
625
+ // app/components/DataProcessor.tsx
626
+ 'use client';
627
+
628
+ import { useEffect, useState } from 'react';
629
+
630
+ function DataProcessor({ data }: { data: number[] }) {
631
+ const [result, setResult] = useState<number | null>(null);
632
+
633
+ useEffect(() => {
634
+ const worker = new Worker(new URL('../workers/processor.js', import.meta.url));
635
+
636
+ worker.postMessage(data);
637
+ worker.onmessage = (e) => setResult(e.data);
638
+
639
+ return () => worker.terminate();
640
+ }, [data]);
641
+
642
+ return <div>Result: {result}</div>;
643
+ }
644
+ ```
645
+
646
+ ### Measuring Performance
647
+
648
+ ```tsx
649
+ // app/components/PerformanceMonitor.tsx
650
+ 'use client';
651
+
652
+ import { useReportWebVitals } from 'next/web-vitals';
653
+
654
+ export function PerformanceMonitor() {
655
+ useReportWebVitals((metric) => {
656
+ switch (metric.name) {
657
+ case 'LCP':
658
+ console.log('LCP:', metric.value);
659
+ break;
660
+ case 'FID':
661
+ console.log('FID:', metric.value);
662
+ break;
663
+ case 'CLS':
664
+ console.log('CLS:', metric.value);
665
+ break;
666
+ case 'TTFB':
667
+ console.log('TTFB:', metric.value);
668
+ break;
669
+ }
670
+
671
+ // Send to analytics
672
+ analytics.track('web-vital', {
673
+ name: metric.name,
674
+ value: metric.value,
675
+ id: metric.id,
676
+ });
677
+ });
678
+
679
+ return null;
680
+ }
681
+ ```
682
+
683
+ ---
684
+
685
+ ## Quick Reference
686
+
687
+ ### Performance Checklist
688
+
689
+ | Area | Optimization | Impact |
690
+ |------|-------------|--------|
691
+ | Images | Use next/image with priority for LCP | High |
692
+ | Fonts | Use next/font with display: swap | Medium |
693
+ | Code | Dynamic imports for heavy components | High |
694
+ | Data | Parallel fetching with Promise.all | High |
695
+ | Render | Server Components by default | High |
696
+ | Cache | Configure revalidate appropriately | Medium |
697
+ | Bundle | Tree-shake imports, analyze size | Medium |
698
+
699
+ ### Config Template
700
+
701
+ ```js
702
+ // next.config.js
703
+ /** @type {import('next').NextConfig} */
704
+ const nextConfig = {
705
+ images: {
706
+ remotePatterns: [{ hostname: 'cdn.example.com' }],
707
+ formats: ['image/avif', 'image/webp'],
708
+ },
709
+ experimental: {
710
+ optimizePackageImports: ['lucide-react'],
711
+ },
712
+ headers: async () => [
713
+ {
714
+ source: '/(.*)',
715
+ headers: [
716
+ { key: 'X-Content-Type-Options', value: 'nosniff' },
717
+ { key: 'X-Frame-Options', value: 'DENY' },
718
+ ],
719
+ },
720
+ ],
721
+ };
722
+
723
+ module.exports = nextConfig;
724
+ ```