{
"name": "cloudflare-vite-get-started",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "npm run build && vite preview",
"deploy": "npm run build && wrangler deploy"
}
}npm i -D vite @cloudflare/vite-plugin wrangleryarn add -D vite @cloudflare/vite-plugin wranglerpnpm add -D vite @cloudflare/vite-plugin wranglerbun add -d vite @cloudflare/vite-plugin wranglerimport { defineConfig } from "vite";
import { cloudflare } from "@cloudflare/vite-plugin";
export default defineConfig({
plugins: [cloudflare({ viteEnvironment: { name: "worker" } })],
environments: {
worker: { build: { sourcemap: true } },
},
});The Cloudflare Vite plugin looks for a wrangler.jsonc, wrangler.json or wrangler.toml in the root of your application.
Refer to the API reference for configuration options.
{
"$schema": "./node_modules/wrangler/config-schema.json",
"name": "cloudflare-vite-get-started",
// Set this to today's date
"compatibility_date": "2026-10-19",
"main": "./src/index.ts",
"upload_source_maps": true
}"$schema" = "./node_modules/wrangler/config-schema.json"
name = "cloudflare-vite-get-started"
# Set this to today's date
compatibility_date = "2026-10-19"
main = "./src/index.ts"
upload_source_maps = trueThe name field specifies the name of your Worker.
The viteEnvironment.name option in the Vite configuration above sets the Worker's Vite Environment to worker. If omitted, the plugin uses the Worker name (see Vite Environments for more information).
The main field specifies the entry file for your Worker code.
For more information about the Worker configuration, see Configuration.
The worker environment generates source maps for your Worker. The client environment keeps its existing source map settings.
export default {
fetch() {
return new Response(`Running in ${navigator.userAgent}!`);
},
};A request to this Worker will return 'Running in Cloudflare-Workers!', demonstrating that the code is running inside the Workers runtime.
You can now start the Vite development server (npm run dev), build the application (npm run build), preview the built application (npm run preview), and deploy to Cloudflare (npm run deploy).