---
alwaysApply: true
---

# Deployment and Build Process

## Cloudflare Workers with OpenNext

This project deploys to Cloudflare Workers using OpenNext for Next.js compatibility.

### Build Process

1. **Quality Gates** (run before build):
   ```bash
   npm run type-check  # TypeScript validation
   npm run lint        # ESLint validation
   ```

2. **Production Build**:
   ```bash
   npm run build       # Next.js build
   ```

3. **OpenNext Build**:
   ```bash
   npx open-next@latest build  # Generate Cloudflare-compatible build
   ```

4. **Deploy**:
   ```bash
   npx wrangler deploy .open-next/worker
   ```

### Configuration Files

- [wrangler.toml](mdc:wrangler.toml) - Cloudflare Workers configuration
- [open-next.config.ts](mdc:open-next.config.ts) - OpenNext build configuration
- [next.config.ts](mdc:next.config.ts) - Next.js configuration

### Required wrangler.toml Settings

```toml
name = "site-worker"
main = ".open-next/worker/index.mjs"
compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]
assets = { directory = ".open-next/assets" }
```

## Environment Variables

Create `.env.sample` and keep it synchronized. Typical keys:
```
NEXT_PUBLIC_SITE_URL=
RESEND_API_KEY=
CF_PAGES_URL=
```

**Security**: Never commit real secrets. Use `.env` locally and environment variables in production.

## Build Configuration

- ESLint and TypeScript errors are ignored during build for deployment speed
- CI still gates on `lint` and `type-check` before merge
- Always fix errors instead of bypassing checks

## Deployment Checklist

- [ ] Run `npm run type-check` and `npm run lint`
- [ ] Ensure `assets.directory` matches OpenNext output
- [ ] Keep compatibility date at or after 2024-09-23
- [ ] Test build locally with `npm run build`
- [ ] Verify OpenNext build artifacts in `.open-next/`