> ## Documentation Index
> Fetch the complete documentation index at: https://weaverse.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Weaverse component configuration uses `settings`. `inspector` is deprecated; never generate it.
> Weaverse Hydrogen themes use React Router v7: import from `react-router`, never `react-router-dom` or `@remix-run/*`.
> Before using any code sample, read `@weaverse/hydrogen` in the project's `package.json`: 6.x and 5.x import from different entries and use different type names, so code for one does not build on the other.
> `@weaverse/hydrogen` 6 (Shopify Hydrogen 2026.10 and later, the version these docs show) imports from `@weaverse/hydrogen/react-router` and uses `Weaverse*` types such as `WeaverseComponentProps`, `WeaverseComponentLoaderArgs` and `WeaverseComponentSchema`; the root `@weaverse/hydrogen` entry only exports `createSchema()`, data helpers and types.
> `@weaverse/hydrogen` 5.x (Hydrogen 2026.4 and earlier) imports everything from `@weaverse/hydrogen` and uses `HydrogenComponentProps`, `ComponentLoaderArgs` and `HydrogenComponentSchema`. On a 5.x project, convert samples to these names. Upgrade to 6 only when asked (`npx @weaverse/cli@latest migrate v6`, plus the Hydrogen 2026.10 upgrade). Do not mix major versions.
> Next.js themes use `@weaverse/hydrogen` 6.2.0 or later: import client and shared code from `@weaverse/hydrogen/next` and server-only code from `@weaverse/hydrogen/next/server`. `@weaverse/next` is deprecated; never install or import it.
> For live project data (pages, theme settings, translations), use the Weaverse MCP server: https://weaverse.io/docs/developer-tools/weaverse-mcp

# Deploy to Cloudflare Workers

> Migrate a Weaverse Hydrogen theme from Oxygen to Cloudflare Workers, step by step

# Deploying a Weaverse Theme to Cloudflare Workers

> [!NOTE]
>
> This guide is for Shopify Hydrogen storefronts. Building on Next.js? See the [Next.js overview](https://weaverse.io/docs/nextjs/overview.md).

> [!WARNING]
>
> **This is a migration, not a supported preset.** Weaverse themes (Pilot, Naturelle) ship configured for **Shopify Oxygen** — the Oxygen Vite plugin, Oxygen deployment, and Oxygen worker types. There is **no** Cloudflare plugin, `wrangler` config, Cloudflare worker entry, or `cf-*` script in the theme. Everything on this page is something **you add yourself**.
>
> For production storefronts, use [Shopify Oxygen](https://weaverse.io/docs/guides/deployment/oxygen.md). Only take this path if you have a concrete reason to host on Cloudflare, and budget time to validate the result end to end.

## What your theme ships with today

Before changing anything, it helps to see exactly what you are migrating away from. In the current Pilot theme (Hydrogen 2026.10):

| File | Current state |
| - | - |
| `vite.config.ts` | Uses `...oxygen()` from `@shopify/mini-oxygen/vite` alongside `localHttps()` from `@shopify/hydrogen/vite` and `reactRouter()` |
| `server.ts` | Module-format `fetch(request, env, executionContext)` handler built on React Router's `createRequestHandler`, with Hydrogen's `handleShopifyRoutes` and `handleShopifyRedirects` |
| `react-router.config.ts` | No preset: `ssr: true`, `buildDirectory: "dist"` and the `future` flags Hydrogen needs |
| `env.d.ts` | References `@shopify/oxygen-workers-types` for the worker globals |
| `package.json` | `dev` / `build` / `preview` / `start` run `vite` and `react-router`; `deploy` runs `shopify hydrogen deploy` to Oxygen; `check` is the linter. No `cf-dev`, `cf-typegen`, `cf-check` or `cf-deploy` |
| `wrangler.json` | **Does not exist** |
| `.gitignore` | Already ignores `.env` and `.wrangler/` |

Nothing below is pre-configured. Treat each step as a change you are making to your own fork.

## Prerequisites

* **Node.js**: `^22.18.0 || ^24.11.0` (this is the `engines.node` requirement of the current Pilot theme)
* **Cloudflare account**: sign up at [cloudflare.com](https://cloudflare.com)
* **Shopify store**: active store with Storefront API access
* **Weaverse project**: a configured project ID for your storefront
* A working Oxygen build first — run `npm run build` and confirm it succeeds before you start migrating

## Quick Flow

**1. Add the Cloudflare dependencies**

`npm i -D wrangler @cloudflare/vite-plugin`

**2. Swap the Oxygen Vite plugin for the Cloudflare plugin**

Edit `vite.config.ts`.

**3. Create wrangler.json**

Point `main` at your worker entry and enable `nodejs_compat`.

**4. Add your own npm scripts**

`cf-dev`, `cf-typegen`, `cf-check`, `cf-deploy` — none of these exist yet.

**5. Upload secrets and deploy**

`npx wrangler secret bulk .dev.vars` then `npx wrangler deploy`.

The rest of this page expands each step.

## 1. Install the Cloudflare toolchain

```bash theme={null}
npm install --save-dev wrangler @cloudflare/vite-plugin
```

`@cloudflare/vite-plugin` builds your app for the `workerd` runtime as Cloudflare runs it. `wrangler` is the CLI used to configure, preview, and deploy the worker.

## 2. Update `vite.config.ts`

Your theme currently registers the Oxygen plugin. Replace it with the Cloudflare plugin — running both is not supported, since each one owns the SSR environment.

```diff vite.config.ts theme={null}
  import { reactRouter } from "@react-router/dev/vite";
+ import { cloudflare } from "@cloudflare/vite-plugin";
  import { localHttps } from "@shopify/hydrogen/vite";
- import { oxygen } from "@shopify/mini-oxygen/vite";
  import tailwindcss from "@tailwindcss/vite";
  import { defineConfig } from "vite";

  export default defineConfig(({ isSsrBuild }) => ({
    plugins: [
      localHttps({ enabled: process.env.npm_lifecycle_event === "dev:https" }),
-     ...oxygen(),
+     cloudflare({ viteEnvironment: { name: "ssr" } }),
      reactRouter(),
      tailwindcss(),
    ],
    build: {
      assetsInlineLimit: 0,
    },
    // ...keep the rest of your existing config
  }));
```

> [!NOTE]
>
> Keep `assetsInlineLimit: 0`. Pilot sets this so no asset is inlined as a data URI, which keeps the storefront compatible with a strict Content-Security-Policy. See [Content Security Policy](https://weaverse.io/docs/features/content-security.md).

Removing `oxygen()` also removes the local Oxygen preview that `npm run dev` and `npm run preview` rely on. Decide up front whether you are keeping an Oxygen path for local development or moving entirely to `wrangler dev`.

## 3. Review your worker entry

`server.ts` already exports a module-format worker — a default object with an `async fetch(request, env, executionContext)` method — which is the shape Cloudflare Workers expects. On Hydrogen 2026.10 it uses React Router's own `createRequestHandler`, so there is no Oxygen request handler to replace. What is still Oxygen-specific:

* `env.d.ts` pulls worker globals from `@shopify/oxygen-workers-types`
* `createAppContext()` in `app/.server/context.ts` reads Oxygen's `env` binding shape, opens the Cache API with `caches.open()`, and reads the buyer IP from Oxygen's `oxygen-buyer-ip` header for the private Storefront client (it falls back to the public client without it)

> [!WARNING]
>
> Shopify does not publish a Cloudflare Workers entry for Hydrogen. You will need to verify that session storage, caching, and the buyer IP header behave correctly on Cloudflare, and adjust `server.ts` and `app/.server/context.ts` if they do not. Test this before pointing production traffic at it.

## 4. Create `wrangler.json`

This file does not exist in the theme — create it in the project root:

```json wrangler.json theme={null}
{
  "$schema": "./node_modules/wrangler/config-schema.json",
  "name": "your-project-name",
  "main": "./server.ts",
  "compatibility_date": "2025-10-08",
  "compatibility_flags": ["nodejs_compat"],
  "keep_vars": true,
  "observability": {
    "enabled": true
  },
  "upload_source_maps": true
}
```

| Field | Purpose |
| - | - |
| `name` | Project name — becomes part of the `*.workers.dev` URL |
| `main` | Worker entry point |
| `compatibility_date` | Pins the `workerd` runtime behavior |
| `compatibility_flags` | `nodejs_compat` is required by Hydrogen's Node built-in usage |
| `keep_vars` | Preserves dashboard-set variables across deploys |
| `observability` | Enables Workers logs and metrics |
| `upload_source_maps` | Readable stack traces in production |

> [!TIP]
>
> If your Cloudflare login has access to multiple accounts, add `"account_id": "<your-cloudflare-account-id>"` so Wrangler does not prompt. Find it in the [Cloudflare Dashboard](https://dash.cloudflare.com) under **Workers & Pages** → **Overview** (right sidebar).

## 5. Configure environment variables

Wrangler reads local development values from `.dev.vars`. Create one from your existing `.env` values:

```text .dev.vars theme={null}
NODE_ENV=production
SESSION_SECRET=your-secure-session-secret
PUBLIC_STORE_DOMAIN=your-shopify-store.myshopify.com
PUBLIC_STOREFRONT_API_TOKEN=your-shopify-storefront-api-token
PUBLIC_CUSTOMER_ACCOUNT_API_CLIENT_ID=your-customer-account-api-client-id
SHOP_ID=your-shop-id
WEAVERSE_PROJECT_ID=your-weaverse-project-id
WEAVERSE_HOST=https://studio.weaverse.io
```

Add any optional variables your theme uses (`JUDGEME_PRIVATE_API_TOKEN`, `KLAVIYO_PRIVATE_API_TOKEN`, `PUBLIC_GOOGLE_GTM_ID`, and so on) — see `.env.example` in your theme for the authoritative list.

Upload them as Worker secrets:

```bash theme={null}
npx wrangler secret bulk .dev.vars
```

> [!NOTE]
>
> Setting `NODE_ENV=production` prevents Hydrogen from injecting its development-only virtual routes into the production build.

> [!WARNING]
>
> Add `.dev.vars` to `.gitignore`. The theme already ignores `.env` and `.wrangler/`, but **not** `.dev.vars` — add it yourself.

## 6. Add npm scripts

None of these scripts exist in the theme. Pilot's own `deploy` (Oxygen) and `check` (lint) scripts keep their names, so prefix the Cloudflare ones. Add the ones you need to `package.json`:

```json package.json theme={null}
{
  "scripts": {
    "cf-typegen": "wrangler types && react-router typegen",
    "cf-dev": "wrangler dev --port 8787",
    "cf-check": "tsc --noEmit && react-router build && wrangler deploy --dry-run",
    "cf-deploy": "wrangler deploy"
  }
}
```

| Script | What it does |
| - | - |
| `cf-typegen` | Generates Worker binding types plus React Router route types |
| `cf-dev` | Runs the app locally in `workerd` on port 8787 |
| `cf-check` | Type check, build, and dry-run deploy — catches config errors before shipping |
| `cf-deploy` | Publishes the worker |

## 7. Deploy

```bash theme={null}
# Authenticate (opens your browser)
npx wrangler login

# Install and build
npm install
npm run build

# Test in the Workers runtime locally
npm run cf-dev

# Validate before shipping
npm run cf-check

# Ship it
npm run cf-deploy
```

Wrangler prints the live URL on success, typically `https://your-project-name.<subdomain>.workers.dev`.

## Post-Deployment

### Stream logs

```bash theme={null}
npx wrangler tail
```

Keep this running during your first smoke test so runtime errors surface immediately.

### Custom domain

1. Open the [Cloudflare Dashboard](https://dash.cloudflare.com)
2. **Workers & Pages** → select your worker
3. **Settings** → **Domains & Routes**
4. Add your domain and configure routes

See also [Custom Domain and DNS](https://weaverse.io/docs/guides/deployment/custom-domain-and-dns.md).

### Git-connected builds

1. **Workers & Pages** → your worker → **Settings** → **Builds**
2. **Connect** a Git repository and authorize access
3. Select the repository and branch
4. Build command `npm run build`, output directory `dist`

### Rollback

```bash theme={null}
npx wrangler deployments list
npx wrangler deployments rollback <deployment-id>
```

> [!WARNING]
>
> A rollback shifts all traffic immediately. Verify the target deployment is healthy first.

## Troubleshooting

**Build fails after removing `oxygen()`**
`npm run dev`, `npm run preview`, and `npm run start` all go through the Shopify CLI's Oxygen sandbox. Once the Oxygen plugin is gone, use `npm run cf-dev` instead.

**`nodejs_compat` errors at runtime**
Confirm the flag is in `wrangler.json` and that `compatibility_date` is recent enough for the Node compatibility mode your dependencies need.

**Missing environment variables in production**
`.dev.vars` is local-only. Values reach production only after `npx wrangler secret bulk .dev.vars`, or by setting them in the dashboard. Names are case-sensitive.

**Weaverse Studio preview does not connect**
Check `WEAVERSE_PROJECT_ID` and `WEAVERSE_HOST` are present as Worker secrets, and that the deployed URL is registered on your Weaverse project. See [Preview Errors](https://weaverse.io/docs/troubleshooting/preview-errors.md).

**Session or cache behaves differently than on Oxygen**
Expected — this is the least-validated part of the migration. Compare against an Oxygen deployment before going live.

## Additional Resources

* [Cloudflare Workers Documentation](https://developers.cloudflare.com/workers/)
* [Wrangler CLI Reference](https://developers.cloudflare.com/workers/wrangler/)
* [Shopify: Self-hosting Hydrogen](https://shopify.dev/docs/storefronts/headless/hydrogen/deployments/self-hosting)
* [Deploy to Oxygen](https://weaverse.io/docs/guides/deployment/oxygen.md) — the supported path
* [Weaverse Community on Slack](https://join.slack.com/t/weaversecommunity/shared_invite/zt-235bv7d80-velzJU8CpZIHWdrzFwAdXg)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.