Get started
Start with a basic package.json
Section titled “Start with a basic package.json”{ "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" }}
Install the dependencies
Section titled “Install the dependencies”npm i -D vite @cloudflare/vite-plugin wrangler
pnpm add -D vite @cloudflare/vite-plugin wrangler
yarn add -D vite @cloudflare/vite-plugin wrangler
Create your Vite config file and include the Cloudflare plugin
Section titled “Create your Vite config file and include the Cloudflare plugin”import { defineConfig } from "vite";import { cloudflare } from "@cloudflare/vite-plugin";
export default defineConfig({ plugins: [cloudflare()],});
The Cloudflare Vite plugin doesn't require any configuration by default and will look for a wrangler.jsonc
, wrangler.json
or wrangler.toml
in the root of your application.
Refer to the API reference for configuration options.
Create your Worker config file
Section titled “Create your Worker config file”{ "name": "cloudflare-vite-get-started", "compatibility_date": "2025-04-03", "main": "./src/index.ts"}
name = "cloudflare-vite-get-started"compatibility_date = "2025-04-03"main = "./src/index.ts"
The name
field specifies the name of your Worker.
By default, this is also used as the name of the Worker's Vite Environment (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.
Create your Worker entry file
Section titled “Create your Worker entry file”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.
Dev, build, preview and deploy
Section titled “Dev, build, preview and deploy”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
).
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark