本页还没有译文
本页 21 段还没译成Español,下面显示的是英文原文。Vike
还没翻译译自英文(developers.cloudflare.com)本页 21 段都还没译
You can deploy your Vike app to Cloudflare using the Vike extension vike-photon.
All app types (SSR/SPA/SSG) are supported.
Already have a Vike project?
Run wrangler deploy in a project without a Wrangler configuration file and Wrangler will automatically detect Vike, generate the necessary configuration, and deploy your project.
npx wrangler deployyarn wrangler deploypnpm wrangler deployLearn more about automatic project configuration.
What is Vike?
Vike is a Next.js/Nuxt alternative for advanced applications, powered by a modular architecture for unprecedented flexibility and stability.
New app
Use vike.dev/new to scaffold a new Vike app that uses vike-photon with @photonjs/cloudflare.
Add to existing app
-
npm i wrangler vike-photon @photonjs/cloudflareyarn add wrangler vike-photon @photonjs/cloudflarepnpm add wrangler vike-photon @photonjs/cloudflarebun add wrangler vike-photon @photonjs/cloudflare -
pages/+config.ts
import type { Config } from 'vike/types' + import vikePhoton from 'vike-photon/config' export default { + extends: [vikePhoton] } satisfies Config -
package.json
{ "scripts": { "dev": "vike dev", + "preview": "vike build && vike preview", + "deploy": "vike build && wrangler deploy" } }wrangler.jsonc+ { + "$schema": "node_modules/wrangler/config-schema.json", + "compatibility_date": "2025-08-06", + "name": "my-vike-cloudflare-app", + "main": "virtual:photon:cloudflare:server-entry", + // Only required if your app depends a Node.js API + "compatibility_flags": ["nodejs_compat"] + } -
.gitignore
+ .wrangler/ -
(Optional) By default, Photon uses a built-in server that supports basic features like SSR. If you need additional server functionalities (e.g. file uploads or API routes), then create your own server.
Cloudflare APIs (bindings)
To access Cloudflare APIs (such as D1 and KV), use bindings which are available via the env object imported from cloudflare:workers.
import { env } from 'cloudflare:workers'
// Key-value store
env.KV.get('my-key')
// Environment variable
env.LOG_LEVEL
// ...Example of using Cloudflare D1:
npm create vike@latest -- --react --hono --drizzle --cloudflareyarn create vike --react --hono --drizzle --cloudflarepnpm create vike@latest --react --hono --drizzle --cloudflareOr go to vike.dev/new and select
Cloudflarewith an ORM.
TypeScript
If you use TypeScript, run wrangler types whenever you change your Cloudflare configuration to update the worker-configuration.d.ts file.
npx wrangler typesyarn wrangler typespnpm wrangler typesThen commit:
git commit -am "update cloudflare types"Make sure TypeScript loads it:
{
"compilerOptions": {
+ "types": ["./worker-configuration.d.ts"]
}
}See also: Cloudflare Workers > TypeScript.