Files

@vinext/cloudflare

Cloudflare deployment tools and runtime adapters for vinext.

This package provides Cloudflare-specific cache and image backends for vinext:

  • kvDataAdapter() (@vinext/cloudflare/cache/kv-data-adapter) — backs the data cache (fetch, "use cache", unstable_cache) with a Workers KV namespace.
  • cdnAdapter() (@vinext/cloudflare/cache/cdn-adapter) — delegates page-level ISR serving and revalidation to Cloudflare Workers Cache through an automatically generated cache-enabled response entrypoint.
  • imagesOptimizer() (@vinext/cloudflare/images/images-optimizer) — backs next/image transformations with a Cloudflare Images binding.

Usage

Declare the adapters on the vinext() plugin in your Vite config:

import { kvDataAdapter } from "@vinext/cloudflare/cache/kv-data-adapter";
import { imagesOptimizer } from "@vinext/cloudflare/images/images-optimizer";

export default defineConfig({
  plugins: [
    vinext({
      cache: {
        data: kvDataAdapter(), // KV-backed data cache (binding: VINEXT_KV_CACHE)
      },
      images: { optimizer: imagesOptimizer() }, // Cloudflare Images binding: IMAGES
    }),
    cloudflare(),
  ],
});

Workers Cache

cdnAdapter() is optional. Configuring it asks the Cloudflare build for two Worker entrypoints: the default entrypoint runs middleware and request-time routing with caching disabled, while VinextCachedResponse lazily loads the render stage with Workers Cache enabled. These settings are written to the generated dist/server/wrangler.json; do not enable Workers Cache on the default entrypoint in your source config.

Version metadata is still required for staged warmup:

{
  "version_metadata": {
    "binding": "CF_VERSION_METADATA",
  },
}
import { cdnAdapter } from "@vinext/cloudflare/cache/cdn-adapter";

vinext({ cache: { cdn: cdnAdapter() } });

The version metadata binding lets staged warmup prove that every discovery, probe, and fill request reached the uploaded Worker version. Wrangler named environments do not inherit version_metadata; repeat the binding inside every env.<name> used with CDN warming.

Use --experimental-warm-cdn-cache for the two-stage deploy. The default flow makes one final fill request per admitted identity. Add --warm-cdn-certify only when you want an opt-in second, header-only request that must prove every planned entry reusable before promotion.

The response entrypoint hashes the complete transport identity into its Workers Cache URL, independently of zone Cache Rules, so distinct query and representation variants cannot collide.

Deploy

Deploy Cloudflare Workers projects with the package CLI:

npx @vinext/cloudflare deploy

With Vite+, use vpx @vinext/cloudflare deploy, or vp exec vinext-cloudflare deploy when running the locally installed bin.