Usage
Options
flag
Deploy to a preview environment instead of production.Creates a temporary preview URL for testing before production deployment.
string
Custom Worker name. Defaults to project name from Worker names must be lowercase alphanumeric with hyphens.
package.json.flag
Skip the build step and deploy existing Useful when you’ve already built and want to deploy quickly.
dist/ output.flag
Generate config files without building or deploying.Shows what files would be created:
wrangler.jsonc, worker/index.ts, vite.config.ts.flag
Show help for this command. Can also use
-h.Experimental: Traffic-aware Pre-Rendering (TPR)
flag
Enable Traffic-aware Pre-Rendering using Cloudflare zone analytics.Pre-renders hot pages into KV cache during deployment based on actual traffic data.
number
default:"90"
Traffic coverage target percentage (0-100).Pre-renders enough pages to cover 95% of actual traffic.
number
default:"1000"
Hard cap on number of pages to pre-render.Prevents excessive KV usage on high-traffic sites.
number
default:"24"
Analytics lookback window in hours.Uses the last 48 hours of traffic data to determine hot pages.
What It Does
The deploy command automates the entire Cloudflare Workers deployment:1. Project Detection
Scans your project to determine:- Router type: App Router vs Pages Router
- ISR usage: Detects
export const revalidatein pages - MDX usage: Checks for
.mdxfiles or@next/mdxconfig - Native modules: Detects modules that need stubbing (
@resvg/resvg-js,satori, etc.) - Existing config: Checks for
wrangler.jsonc,worker/index.ts,vite.config.ts
2. Dependency Installation
Automatically installs required packages if missing:@cloudflare/vite-plugin(always required)wrangler(Cloudflare Workers CLI)@vitejs/plugin-rsc(App Router only)@mdx-js/rollup(if MDX detected)
3. ESM Configuration
Cloudflare Workers requires ESM. vinext automatically:-
Renames CJS config files:
next.config.js→next.config.cjspostcss.config.js→postcss.config.cjs
-
Adds
"type": "module"topackage.json
4. Config File Generation
Generates missing files:wrangler.jsonc
wrangler.jsonc
Cloudflare Workers configuration:If ISR is detected, adds KV namespace:
worker/index.ts (App Router)
worker/index.ts (App Router)
Worker entry for App Router with image optimization:
worker/index.ts (Pages Router)
worker/index.ts (Pages Router)
Worker entry for Pages Router:
vite.config.ts
vite.config.ts
Vite configuration with Cloudflare plugin:If native modules are detected, adds stub aliases:
5. Build for Workers
Runs the Vite build with Cloudflare-specific configuration:@cloudflare/vite-plugin handles Worker-specific bundling.
6. Deploy via Wrangler
Executeswrangler deploy to publish to Cloudflare:
Examples
First Deployment
Deploy to production:Preview Deployment
Deploy to preview environment for testing:https://my-app-preview.example.workers.dev
Custom Worker Name
Deploy with a custom name:Dry Run (See What Would Be Generated)
Skip Build (Deploy Existing Build)
Useful for quick redeployment:Traffic-aware Pre-Rendering
Pre-render hot pages based on analytics:ISR (Incremental Static Regeneration)
If your app uses ISR, vinext automatically:- Detects
export const revalidatein pages - Adds KV namespace binding to
wrangler.jsonc - Configures runtime cache handler
wrangler.jsonc:
Custom Domains
To use a custom domain:- Add your domain in Cloudflare dashboard
- Add route to
wrangler.jsonc:
- Deploy:
Environment Variables
Set secrets using wrangler:.env.production:
CI/CD Integration
GitHub Actions
GitLab CI
Troubleshooting
”No wrangler found”
vinext installs wrangler automatically, but if you see this error:“Invalid Worker name”
Worker names must be lowercase alphanumeric with hyphens:Build Fails with Native Module Error
Some native Node.js modules don’t work in Workers. vinext automatically stubs common ones:@resvg/resvg-jssatorilightningcss@napi-rs/canvassharp
empty-stub.js:
Deploy Fails with “Unauthorized”
Set your Cloudflare API token:- Account.Workers Scripts (Edit)
- Account.Workers KV Storage (Edit, if using ISR)
Pricing
Cloudflare Workers Free tier:- 100,000 requests/day
- 10ms CPU time per request
- Unlimited bandwidth
- Unlimited storage (KV: 1GB free)
- 10 million requests/month (included)
- 50ms CPU time per request
- $0.50 per million requests after
- KV: 10GB included
Most Next.js apps stay within the free tier during development and small-scale production use.
Next Steps
Cloudflare Deployment
Deep dive into Cloudflare Workers deployment
check Command
Check your project for compatibility