Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/cloudflare-vite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cloudflare + Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions examples/cloudflare-vite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "cloudflare-vite",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"react": "^19.2.4",
"react-dom": "^19.2.4"
},
"devDependencies": {
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.4",
"typescript": "^5.2.2",
"vite": "^7.3.1"
}
}
1 change: 1 addition & 0 deletions examples/cloudflare-vite/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions examples/cloudflare-vite/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}

.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}

.card {
padding: 2em;
}
23 changes: 23 additions & 0 deletions examples/cloudflare-vite/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useState } from "react";
import "./App.css";

function App() {
const [count, setCount] = useState(0);

return (
<div>
{" "}
<h1>Cloudflare + Vite + React</h1>
<div className="card">
<button onClick={() => setCount((value) => value + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
</div>
);
}

export default App;
73 changes: 73 additions & 0 deletions examples/cloudflare-vite/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}

a:hover {
color: #535bf2;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}

button:hover {
border-color: #646cff;
}

button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}

a:hover {
color: #747bff;
}

button {
background-color: #f9f9f9;
}
}
10 changes: 10 additions & 0 deletions examples/cloudflare-vite/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
12 changes: 12 additions & 0 deletions examples/cloudflare-vite/src/sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* This file is auto-generated by SST. Do not edit. */
/* tslint:disable */
/* eslint-disable */
/* biome-ignore-all lint: auto-generated */

/// <reference types="vite/client" />
interface ImportMetaEnv {

}
interface ImportMeta {
readonly env: ImportMetaEnv
}
18 changes: 18 additions & 0 deletions examples/cloudflare-vite/sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* This file is auto-generated by SST. Do not edit. */
/* tslint:disable */
/* eslint-disable */
/* deno-fmt-ignore-file */
/* biome-ignore-all lint: auto-generated */

declare module "sst" {
export interface Resource {
"Vite": {
"type": "sst.cloudflare.StaticSite"
"url": string
}
}
}
/// <reference path="sst-env.d.ts" />

import "sst"
export {}
25 changes: 25 additions & 0 deletions examples/cloudflare-vite/sst.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// <reference path="./.sst/platform/config.d.ts" />

/**
* ## React SPA with Vite
*
* Deploy a React single-page app (SPA) with Vite to Cloudflare.
*/
export default $config({
app(input) {
return {
name: "cf-vite",
home: "cloudflare",
removal: input?.stage === "production" ? "retain" : "remove",
};
},
async run() {
new sst.cloudflare.x.StaticSite("Vite", {
build: {
command: "pnpm run build",
output: "dist",
},
notFoundHandling: "single-page-application",
});
},
});
25 changes: 25 additions & 0 deletions examples/cloudflare-vite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
11 changes: 11 additions & 0 deletions examples/cloudflare-vite/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts"]
}
7 changes: 7 additions & 0 deletions examples/cloudflare-vite/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
Loading
Loading