@donotdev/cli 0.1.0 → 0.1.1

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 (93) hide show
  1. package/dependencies-matrix.json +100 -50
  2. package/dist/bin/commands/agent-setup.js +245 -12
  3. package/dist/bin/commands/build.js +3339 -208
  4. package/dist/bin/commands/bump.js +245 -12
  5. package/dist/bin/commands/cacheout.js +245 -12
  6. package/dist/bin/commands/coach.js +361 -60
  7. package/dist/bin/commands/create-app.js +245 -12
  8. package/dist/bin/commands/create-project.js +253 -12
  9. package/dist/bin/commands/db.js +9114 -2327
  10. package/dist/bin/commands/deploy.js +4074 -694
  11. package/dist/bin/commands/dev.js +347 -33
  12. package/dist/bin/commands/doctor.js +408 -107
  13. package/dist/bin/commands/emu.js +386 -52
  14. package/dist/bin/commands/format.js +245 -12
  15. package/dist/bin/commands/get-demo.js +245 -12
  16. package/dist/bin/commands/make-admin.js +8356 -1516
  17. package/dist/bin/commands/preview.js +347 -33
  18. package/dist/bin/commands/seed.js +9114 -2327
  19. package/dist/bin/commands/setup-cicd.js +452 -132
  20. package/dist/bin/commands/setup.js +407 -107
  21. package/dist/bin/commands/staging.js +4074 -694
  22. package/dist/bin/commands/sync-secrets.js +246 -13
  23. package/dist/bin/commands/type-check.js +245 -12
  24. package/dist/bin/commands/wai.js +245 -12
  25. package/dist/bin/dndev.js +13 -4
  26. package/dist/bin/donotdev.js +13 -4
  27. package/dist/index.js +4169 -812
  28. package/{templates/root-consumer/guides/dndev/advanced/VERSION_CONTROL.md.example → guidelines/VERSION_CONTROL.md} +7 -11
  29. package/package.json +2 -1
  30. package/templates/app-demo/src/themes.css.example +21 -0
  31. package/templates/app-dndev/index.html.example +0 -3
  32. package/templates/app-dndev/src/themes.css.example +21 -0
  33. package/templates/app-next/src/app/layout.tsx.example +13 -4
  34. package/templates/app-next/src/themes.css.example +21 -0
  35. package/templates/app-vite/csp.example.json +44 -0
  36. package/templates/app-vite/index.html.example +0 -3
  37. package/templates/app-vite/src/themes.css.example +21 -0
  38. package/templates/functions-supabase/supabase/migrations/20250101000000_idempotency.sql +3 -0
  39. package/templates/functions-supabase/supabase/migrations/20250101000001_rate_limits.sql +3 -0
  40. package/templates/functions-supabase/supabase/migrations/20250101000003_operation_metrics.sql +3 -0
  41. package/templates/root-consumer/.claude/hooks/framework-compliance.sh.example +56 -0
  42. package/templates/root-consumer/.claude/hooks/guard-bash.sh.example +61 -0
  43. package/templates/root-consumer/.claude/hooks/guard-files.sh.example +46 -0
  44. package/templates/root-consumer/.claude/hooks/guard-mcp.sh.example +91 -0
  45. package/templates/root-consumer/.claude/hooks/guard-secrets.sh.example +67 -0
  46. package/templates/root-consumer/.claude/hooks/guard-write.sh.example +89 -0
  47. package/templates/root-consumer/.claude/hooks/session-start.sh.example +50 -0
  48. package/templates/root-consumer/.claude/hooks/track-mcp-lookup.sh.example +20 -0
  49. package/templates/root-consumer/.claude/hooks/typecheck-stop.sh.example +18 -0
  50. package/templates/root-consumer/.claude/rules/consumer-ux.md.example +32 -0
  51. package/templates/root-consumer/.claude/rules/definition-of-done.md.example +32 -0
  52. package/templates/root-consumer/.claude/rules/framework.md.example +39 -0
  53. package/templates/root-consumer/.claude/rules/git.md.example +14 -0
  54. package/templates/root-consumer/.claude/rules/security.md.example +13 -0
  55. package/templates/root-consumer/.claude/settings.json.example +123 -1
  56. package/templates/root-consumer/.claude/skills/build/SKILL.md.example +103 -25
  57. package/templates/root-consumer/.claude/skills/grill/SKILL.md.example +26 -15
  58. package/templates/root-consumer/.claude/skills/polish/SKILL.md.example +50 -37
  59. package/templates/root-consumer/AI.md.example +2 -2
  60. package/templates/root-consumer/CLAUDE.md.example +33 -1
  61. package/templates/root-consumer/guides/dndev/INDEX.md.example +23 -27
  62. package/templates/root-consumer/guides/dndev/SETUP_AUTH.md.example +3 -2
  63. package/templates/root-consumer/guides/dndev/SETUP_OAUTH.md.example +10 -5
  64. package/templates/root-consumer/guides/dndev/SETUP_SUPABASE.md.example +50 -3
  65. package/templates/root-consumer/guides/wai-way/blueprints/3_compose.md.example +13 -15
  66. package/templates/app-demo/public/manifest.json.example +0 -10
  67. package/templates/app-dndev/public/manifest.json.example +0 -10
  68. package/templates/root-consumer/.claude/commands/brainstorm.md.example +0 -175
  69. package/templates/root-consumer/.claude/commands/build.md.example +0 -131
  70. package/templates/root-consumer/.claude/commands/design.md.example +0 -184
  71. package/templates/root-consumer/.claude/commands/grill.md.example +0 -135
  72. package/templates/root-consumer/.claude/commands/polish.md.example +0 -146
  73. package/templates/root-consumer/.claude/commands/techdebt.md.example +0 -28
  74. package/templates/root-consumer/guides/dndev/COMPONENTS_ATOMIC.md.example +0 -180
  75. package/templates/root-consumer/guides/dndev/COMPONENTS_CRUD.md.example +0 -234
  76. package/templates/root-consumer/guides/dndev/COMPONENTS_UI.md.example +0 -136
  77. package/templates/root-consumer/guides/dndev/COMPONENT_API.md.example +0 -195
  78. package/templates/root-consumer/guides/dndev/ENV_SETUP.md.example +0 -219
  79. package/templates/root-consumer/guides/dndev/GOTCHAS.md.example +0 -197
  80. package/templates/root-consumer/guides/dndev/SETUP_APP_CONFIG.md.example +0 -132
  81. package/templates/root-consumer/guides/dndev/SETUP_BLOG.md.example +0 -280
  82. package/templates/root-consumer/guides/dndev/SETUP_CICD.md.example +0 -115
  83. package/templates/root-consumer/guides/dndev/SETUP_CRUD.md.example +0 -334
  84. package/templates/root-consumer/guides/dndev/SETUP_FUNCTIONS.md.example +0 -9
  85. package/templates/root-consumer/guides/dndev/SETUP_I18N.md.example +0 -233
  86. package/templates/root-consumer/guides/dndev/SETUP_LAYOUTS.md.example +0 -158
  87. package/templates/root-consumer/guides/dndev/SETUP_PAGES.md.example +0 -205
  88. package/templates/root-consumer/guides/dndev/SETUP_PWA.md.example +0 -213
  89. package/templates/root-consumer/guides/dndev/SETUP_TESTING.md.example +0 -184
  90. package/templates/root-consumer/guides/dndev/SETUP_THEMES.md.example +0 -111
  91. package/templates/root-consumer/guides/dndev/SETUP_VERCEL.md.example +0 -260
  92. package/templates/root-consumer/guides/dndev/USE_ROUTING.md.example +0 -499
  93. package/templates/root-consumer/guides/dndev/essences_reference.css.example +0 -288
@@ -1,158 +0,0 @@
1
- # Setup: Layouts
2
-
3
- **Most is pre-configured.** Choose preset in `config/app.ts`. Framework handles header, sidebar, footer, auth, themes, languages.
4
-
5
- ---
6
-
7
- ## Standard Use
8
-
9
- **Choose preset:**
10
- ```typescript
11
- // config/app.ts
12
- export const appConfig: AppConfig = {
13
- preset: 'landing', // landing | admin | moolti | docs | blog | game | plain
14
- };
15
- ```
16
-
17
- **7 presets:** `landing` (marketing), `admin` (dashboards), `moolti` (SaaS), `docs` (documentation), `blog` (content), `game` (mobile), `plain` (minimal).
18
-
19
- ---
20
-
21
- ## Preset Capabilities
22
-
23
- **The `docs` preset AUTOMATICALLY generates sidebar navigation from your `src/pages` files. You do not need to configure a sidebar manually.**
24
-
25
- All presets automatically include these components when applicable:
26
-
27
- * **LanguageSelector** - Automatically shown if more than 1 language is configured
28
- * **ThemeToggle** - Automatically shown if more than 1 theme is available
29
- * **AuthMenu** - Automatically shown if auth is configured in `.env` (Firebase keys present)
30
- * **Navigation Menu** - Automatically generated from `src/pages/*Page.tsx` files for sidebars
31
- * **GoTo Component** - Command palette (Cmd+K) for quick navigation - always available
32
- * **Footer** - Automatic footer with copyright and legal links
33
- * **LegalLinks + Copyright** - Automatically included in footer from `config/legal.ts`
34
-
35
- **You don't need to add these manually - the framework handles them based on your configuration.**
36
-
37
- ---
38
-
39
- ## Per-Route Layout Switching
40
-
41
- **Override the app preset on a per-page basis via `PageMeta.preset`:**
42
-
43
- ```tsx
44
- // src/pages/DashboardPage.tsx
45
- import type { PageMeta } from '@donotdev/core';
46
-
47
- export const meta: PageMeta = {
48
- preset: 'admin', // This route uses admin layout (sidebar, compact density)
49
- auth: true,
50
- };
51
- ```
52
-
53
- - If `preset` is set → that route uses the specified layout
54
- - If `preset` is absent → the app's `appConfig.preset` is used
55
- - The override is **transient** — navigating away restores the next route's preset or the app default
56
- - No localStorage pollution — route presets are not persisted
57
-
58
- **Common pattern (SaaS app):**
59
- | Route | Preset | Purpose |
60
- |-------|--------|---------|
61
- | `/` | (app default: `landing`) | Marketing landing page |
62
- | `/pricing` | (app default: `landing`) | Pricing page |
63
- | `/dashboard` | `admin` | Dashboard with sidebar |
64
- | `/products` | `admin` | CRUD with sidebar |
65
- | `/changelog` | `docs` | Documentation layout |
66
-
67
- **Reference implementation:** See `packages/cli/templates/app-demo/` for a working example of per-route switching.
68
-
69
- ---
70
-
71
- ## Advanced: Slot Overrides
72
-
73
- **Customize zones:**
74
- ```tsx
75
- <ViteAppProviders
76
- config={appConfig}
77
- layout={{
78
- header: {
79
- start: () => <CustomLogo />, // Override start zone
80
- center: () => <SearchBar />, // Override center zone
81
- end: () => <UserMenu />, // Override end zone
82
- },
83
- sidebar: {
84
- top: () => <Branding />, // Override top zone
85
- content: () => <CustomNav />, // Override content zone
86
- bottom: () => <UserProfile />, // Override bottom zone
87
- },
88
- footer: () => <CustomFooter />, // Replace entire footer
89
- }}
90
- />
91
- ```
92
-
93
- **Hide zones:**
94
- ```tsx
95
- layout={{
96
- header: {
97
- center: () => null, // Hide center zone
98
- },
99
- footer: () => null, // Hide footer
100
- }}
101
- ```
102
-
103
- **Available slots:** `header.start/center/end`, `sidebar.top/content/bottom`, `footer`, `mergedbar` (mobile nav).
104
-
105
- ---
106
-
107
- ## Advanced: CSS Variable Overrides
108
-
109
- **Override dimensions in `src/themes.css`:**
110
- ```css
111
- :root {
112
- --header-height: 96px;
113
- --sidebar-width: 320px;
114
- --main-max-width: 1480px;
115
- --footer-height: 64px;
116
- --section-gap: 2rem;
117
- }
118
- ```
119
-
120
- **Framework auto-computes:** Spacing, typography, responsive breakpoints.
121
-
122
- ---
123
-
124
- ## Advanced: Density System
125
-
126
- **Global density:**
127
- ```tsx
128
- layout={{
129
- density: 'compact', // compact | standard | expressive
130
- }}
131
- ```
132
-
133
- **Per-page density:**
134
- ```tsx
135
- <PageContainer density="expressive">
136
- <HeroSection title="Hero" />
137
- </PageContainer>
138
- ```
139
-
140
- **Three densities:** `compact` (1.2×), `standard` (1.25×), `expressive` (1.333×).
141
-
142
- ---
143
-
144
- ## Advanced: Runtime Preset Changes
145
-
146
- **Change preset programmatically:**
147
- ```tsx
148
- import { useLayout } from '@donotdev/core';
149
-
150
- const setLayoutPreset = useLayout('setLayoutPreset');
151
- setLayoutPreset('plain'); // Switch to plain layout
152
- ```
153
-
154
- **Pre-configured:** All presets handle auth, themes, languages automatically.
155
-
156
- ---
157
-
158
- **Choose preset, get layout. Framework handles the rest.**
@@ -1,205 +0,0 @@
1
- # Setup: Pages & Routing
2
-
3
- **Most is pre-configured.** Drop `*Page.tsx` files. Routes auto-discovered, navigation auto-generated, sitemap auto-built.
4
-
5
- ---
6
-
7
- ## File Routing Rule
8
-
9
- **CRITICAL: Only files ending in `Page.tsx` inside `src/pages` become routes.**
10
-
11
- Files must be named `*Page.tsx` (e.g., `HomePage.tsx`, `AboutPage.tsx`, `BlogPostPage.tsx`). Files without the `Page.tsx` suffix are ignored by the routing system.
12
-
13
- ---
14
-
15
- ## Standard Use
16
-
17
- **Pattern:** `src/pages/**/*Page.tsx` → routes
18
-
19
- **Basic page structure:**
20
- ```tsx
21
- // src/pages/AboutPage.tsx
22
- import { PageContainer } from '@donotdev/ui';
23
-
24
- export const NAMESPACE = 'about';
25
-
26
- export const meta: PageMeta = {
27
- namespace: NAMESPACE,
28
- };
29
-
30
- export default function AboutPage() {
31
- return <PageContainer><h1>About</h1></PageContainer>;
32
- }
33
- ```
34
-
35
- **Cookie-cutter pattern (Landing page):**
36
- ```tsx
37
- import { PageContainer } from '@donotdev/ui';
38
- import { HeroSection, Section, Card, CallToAction } from '@donotdev/components';
39
-
40
- export default function HomePage() {
41
- return (
42
- <PageContainer>
43
- <HeroSection title="Welcome" subtitle="Build fast" variant="primary" />
44
- <Section title="Features" gridCols={3}>
45
- <Card title="Fast" />
46
- <Card title="Simple" />
47
- <Card title="Powerful" />
48
- </Section>
49
- <CallToAction title="Get Started" primaryAction={<Button>Sign Up</Button>} />
50
- </PageContainer>
51
- );
52
- }
53
- ```
54
-
55
- **Drop files, get routes. No config needed.**
56
-
57
- **Component reference:** See [COMPONENTS_ATOMIC.md](./COMPONENTS_ATOMIC.md) for atomic components, [COMPONENTS_UI.md](./COMPONENTS_UI.md) for layout components.
58
-
59
- ---
60
-
61
- ## Advanced: All PageMeta Props
62
-
63
- ```tsx
64
- export const meta: PageMeta = {
65
- // Translation/SEO namespace
66
- namespace: NAMESPACE,
67
-
68
- // Route configuration
69
- route: '/custom-url', // Override auto-generated path
70
- route: { params: ['slug'] }, // Dynamic: /blog/:slug
71
-
72
- // Page title (optional - auto-extracted from filename)
73
- title: 'Custom Title',
74
-
75
- // Navigation icon (lucide-react JSX only)
76
- icon: <Rocket />, // Menu icon (default: Link)
77
-
78
- // Hide from navigation menu
79
- hideFromMenu: false, // Default: false (shows in nav)
80
-
81
- // Layout preset override (per-route)
82
- preset: 'admin', // Override app default for this route
83
-
84
- // Authentication
85
- auth: true, // Simple: auth required
86
- auth: { required: true }, // Explicit: auth required
87
- auth: { required: true, role: 'admin' }, // Role-based access
88
- auth: { required: true, tier: 'pro' }, // Tier-based access
89
- auth: {
90
- required: true,
91
- validate: (role, tier) => role === 'admin' && tier === 'pro'
92
- }, // Custom validation
93
- };
94
- ```
95
-
96
- **Reference implementation:** The demo app (`packages/cli/templates/app-demo/`) shows all these patterns working together — landing, admin, docs presets, auth, showcase, CRUD, legal pages.
97
-
98
- ---
99
-
100
- ## Advanced: Dynamic Routes & Navigation
101
-
102
- ```tsx
103
- // Dynamic route
104
- export const meta: PageMeta = {
105
- namespace: 'blog',
106
- route: { params: ['slug'] }, // → /blog/:slug
107
- };
108
-
109
- export default function BlogPostPage() {
110
- const { slug } = useParams<{ slug: string }>();
111
- return <PageContainer><h1>{slug}</h1></PageContainer>;
112
- }
113
-
114
- // Manual navigation
115
- import { useNavigate, Link } from '@donotdev/ui';
116
- const navigate = useNavigate();
117
- navigate('/about');
118
- <Link path="/about">About</Link>
119
-
120
- // Card with navigation (supports middle-click)
121
- import { Card } from '@donotdev/components';
122
- import { Link } from '@donotdev/ui';
123
-
124
- <Link
125
- path="/about"
126
- style={{ display: 'block', textDecoration: 'none', height: '100%' }}
127
- aria-label="Learn more about About"
128
- >
129
- <Card title="About" subtitle="Learn more" />
130
- </Link>
131
- ```
132
-
133
- **Navigation patterns:**
134
- - **Link component:** Use for text links, buttons, or wrapping other components
135
- - **Card navigation:** Wrap Card in Link for clickable cards with middle-click support
136
- - **onClick only:** Use `onClick={() => navigate()}` for actions that don't need middle-click
137
-
138
- **Pre-configured:** Navigation menu auto-generated, sitemap auto-built (if `generateSitemap: true`).
139
-
140
- ---
141
-
142
- ---
143
-
144
- ## Import Convention
145
-
146
- **Always import from `@donotdev/<package>` top-level.** Never use sub-paths.
147
-
148
- ```tsx
149
- import { PageContainer, Link, useNavigate } from '@donotdev/ui';
150
- import { Card, Button, Input } from '@donotdev/components';
151
- import { useCrud } from '@donotdev/crud';
152
- ```
153
-
154
- **Sub-path exceptions** (server, config, and provider-specific):
155
- - **Server:** `@donotdev/core/server`, `@donotdev/firebase/server`, `@donotdev/security/server`
156
- - **Config:** `@donotdev/core/vite`, `@donotdev/core/next`, `@donotdev/core/functions`
157
- - **Functions:** `@donotdev/functions/firebase`, `@donotdev/functions/vercel`, `@donotdev/functions/supabase`
158
-
159
- ---
160
-
161
- ## SaaS App Pattern
162
-
163
- For SaaS apps, the standard page structure is:
164
-
165
- ```
166
- src/pages/
167
- HomePage.tsx → / → No auth. Login form OR landing page.
168
- Redirects to /dashboard when authenticated.
169
- DashboardPage.tsx → /dashboard → auth: true. Main landing for logged-in users.
170
- SettingsPage.tsx → /settings → auth: true.
171
- ...
172
- ```
173
-
174
- **HomePage is never auth-guarded.** It's the entry point for unauthenticated users. Do NOT create a separate `LoginPage` — HomePage IS the login.
175
-
176
- ```tsx
177
- // src/pages/HomePage.tsx — SaaS pattern
178
- import { useAuthSafe, useNavigate, PageContainer } from '@donotdev/ui';
179
- import { LoginForm } from '@donotdev/templates';
180
-
181
- export const meta: PageMeta = {
182
- namespace: 'home',
183
- // No auth — this is the public entry point
184
- };
185
-
186
- export default function HomePage() {
187
- const user = useAuthSafe('user');
188
- const navigate = useNavigate();
189
-
190
- // Redirect authenticated users to dashboard
191
- if (user) { navigate('/dashboard'); return null; }
192
-
193
- return (
194
- <PageContainer>
195
- <LoginForm onSuccess={() => navigate('/dashboard')} />
196
- </PageContainer>
197
- );
198
- }
199
- ```
200
-
201
- > **Why `useAuthSafe` instead of `useAuth`?** HomePage is public — it renders before auth is guaranteed to be initialized. `useAuthSafe` (from `@donotdev/ui`) gracefully degrades if `@donotdev/auth` isn't installed or still initializing. `useAuth` (from `@donotdev/auth`) throws if auth isn't available. Use `useAuthSafe` on any page without `auth: true` in its meta.
202
-
203
- ---
204
-
205
- **Drop files, get routes. Framework handles the rest.**
@@ -1,213 +0,0 @@
1
- # PWA Setup
2
-
3
- **For AI Agents:** Enable PWA in config, add required app metadata. Framework handles service worker, manifest, and caching.
4
-
5
- ---
6
-
7
- ## Quick Start
8
-
9
- ### 1. Add Required App Metadata
10
-
11
- PWA requires `name`, `shortName`, and `description` in your app config:
12
-
13
- ```typescript
14
- // src/config/app.ts
15
- import type { AppConfig } from '@donotdev/core';
16
-
17
- export const appConfig: AppConfig = {
18
- app: {
19
- name: 'My App', // Full app name (required for PWA)
20
- shortName: 'App', // Short name for home screen (required for PWA)
21
- description: 'My app description', // App description (required for PWA)
22
- url: 'https://myapp.com',
23
- },
24
- // ... rest of config
25
- };
26
- ```
27
-
28
- ### 2. Enable PWA in Build Config
29
-
30
- **For Vite apps:**
31
-
32
- ```typescript
33
- // vite.config.ts
34
- import { defineViteConfig } from '@donotdev/core/vite';
35
- import { appConfig } from './src/config/app';
36
-
37
- export default defineViteConfig({
38
- appConfig,
39
- pwa: {
40
- enabled: true, // Enable PWA in production builds
41
- devEnabled: false, // Enable PWA in development (optional)
42
- },
43
- });
44
- ```
45
-
46
- **For Next.js apps:**
47
-
48
- ```typescript
49
- // next.config.ts
50
- import { defineNextConfig } from '@donotdev/core/next';
51
- import { appConfig } from './src/config/app';
52
-
53
- export default defineNextConfig({
54
- appConfig,
55
- pwa: {
56
- enabled: true, // Enable PWA in production builds
57
- devEnabled: false, // Enable PWA in development (optional)
58
- },
59
- });
60
- ```
61
-
62
- **Done.** Framework automatically:
63
- - Generates `manifest.json` from app metadata
64
- - Creates service worker with Workbox
65
- - Discovers and precaches app icons
66
- - Sets up offline caching strategies
67
-
68
- ---
69
-
70
- ## What Gets Auto-Generated
71
-
72
- ### Manifest (`manifest.json`)
73
- - **Name & description:** From `appConfig.app.name`, `shortName`, `description`
74
- - **Icons:** Auto-discovered from `public/` folder (favicon, apple-touch-icon, etc.)
75
- - **Theme colors:** Defaults to white background, black theme (customizable)
76
- - **Display mode:** `standalone` (app-like experience)
77
-
78
- ### Service Worker (`sw.js`)
79
- - **Precaching:** All JS, CSS, HTML, icons, and fonts
80
- - **Runtime caching:** Smart defaults for API calls and images
81
- - **Offline support:** Navigation fallback to `/`
82
- - **Update strategy:** Prompts user to update when new version available
83
-
84
- ### Icons
85
- Framework discovers icons from:
86
- - `public/favicon.svg` or `public/favicon.ico`
87
- - `public/apple-touch-icon.png`
88
- - Any icons generated by AssetPlugin
89
-
90
- ---
91
-
92
- ## Optional Configuration
93
-
94
- ### Custom Manifest Values
95
-
96
- ```typescript
97
- // vite.config.ts or next.config.ts
98
- export default defineViteConfig({
99
- appConfig,
100
- pwa: {
101
- enabled: true,
102
- manifest: {
103
- // Override any manifest values
104
- theme_color: '#667eea',
105
- background_color: '#ffffff',
106
- display: 'standalone',
107
- orientation: 'portrait',
108
- },
109
- },
110
- });
111
- ```
112
-
113
- ### Custom Workbox Configuration
114
-
115
- ```typescript
116
- pwa: {
117
- enabled: true,
118
- workbox: {
119
- // Maximum file size to cache (default: 5MB)
120
- maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
121
-
122
- // Custom precache patterns
123
- globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'],
124
- globIgnores: ['**/node_modules/**'],
125
-
126
- // Runtime caching strategies
127
- runtimeCaching: [
128
- {
129
- urlPattern: /^https:\/\/api\.example\.com\/.*/i,
130
- handler: 'NetworkFirst',
131
- options: {
132
- cacheName: 'api-cache',
133
- expiration: {
134
- maxEntries: 50,
135
- maxAgeSeconds: 60 * 60, // 1 hour
136
- },
137
- },
138
- },
139
- ],
140
- },
141
- },
142
- ```
143
-
144
- ### Development Mode
145
-
146
- Enable PWA in development for testing:
147
-
148
- ```typescript
149
- pwa: {
150
- enabled: true,
151
- devEnabled: true, // Enable service worker in dev mode
152
- debug: true, // Enable debug logging
153
- },
154
- ```
155
-
156
- **Note:** Service workers require HTTPS (or localhost). Use `server: { https: true }` in Vite config for local HTTPS.
157
-
158
- ---
159
-
160
- ## Testing PWA
161
-
162
- 1. **Build for production:**
163
- ```bash
164
- bun run build
165
- ```
166
-
167
- 2. **Serve production build:**
168
- ```bash
169
- bun run preview # Vite
170
- # or
171
- bun run start # Next.js
172
- ```
173
-
174
- 3. **Test in browser:**
175
- - Open DevTools → Application → Service Workers
176
- - Check "Offline" checkbox to test offline mode
177
- - Verify manifest in Application → Manifest
178
- - Test "Add to Home Screen" prompt
179
-
180
- ---
181
-
182
- ## Requirements Checklist
183
-
184
- - [ ] `appConfig.app.name` defined
185
- - [ ] `appConfig.app.shortName` defined
186
- - [ ] `appConfig.app.description` defined
187
- - [ ] `pwa.enabled: true` in build config
188
- - [ ] Icons in `public/` folder (auto-discovered)
189
- - [ ] HTTPS in production (required for service workers)
190
-
191
- ---
192
-
193
- ## Troubleshooting
194
-
195
- **PWA not working:**
196
- - Check browser console for service worker errors
197
- - Verify HTTPS (required except localhost)
198
- - Check manifest.json exists in build output
199
- - Verify app metadata is complete
200
-
201
- **Icons not showing:**
202
- - Ensure icons exist in `public/` folder
203
- - Check icon formats (SVG, PNG, ICO supported)
204
- - Verify AssetPlugin discovered icons (check build logs)
205
-
206
- **Service worker not registering:**
207
- - Check browser console for registration errors
208
- - Verify HTTPS (service workers require secure context)
209
- - Clear browser cache and hard refresh
210
-
211
- ---
212
-
213
- **Zero config. Override when needed.**