Skip to content
Merged
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
79 changes: 71 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,73 @@
# vite-react-boilerplate

[Vercel's Vite - React template](https://github.com/vercel/examples/tree/main/framework-boilerplates/vite-react) on
**Cloudflare Workers**, deployed by [Orun](https://github.com/sourceplane/orun) to stage
and prod on every merge, and then packaged as an Orun baseline.

This commit is the repository's frame: `intent.yaml` (with the placeholder
workspace `ws_CHANGE_ME`, so CI plans nothing until it is linked), the Orun
CI workflow, the shared TypeScript and ESLint configuration, and the spec
index. The work is tracked as an epic under [`specs/epics`](specs/epics/README.md).
Vercel's [Vite - React](https://github.com/vercel/examples/tree/main/framework-boilerplates/vite-react)
template — create-vite's React and TypeScript welcome page, with the Vite and
React logos, its counter and its HMR hint — on Vite 5 and React 18 as the
template has them, running on **Cloudflare Workers + Static Assets**, deployed by
[Orun](https://github.com/sourceplane/orun) to stage and prod on every merge.
Packaging it as an Orun baseline is the next milestone (VR2).

Vite builds fully static: `tsc -b && vite build` writes the app's shell, its
hashed JavaScript bundle and stylesheet and the React logo under `assets/`,
and the Vite logo, to `dist`. That folder is uploaded as Workers Static Assets
with one small Worker in front, and the app is served as a single-page app:
every page address is answered with the app, and a missing file is a 404. The
welcome page, its styles and its entry do not change; the app's name moves
into one module, which the page's heading and the tab's title read, and the
template, which ships no tests, gains a Vitest spec of the page as it
behaves. See [`specs/epics/vite-react-boilerplate`](specs/epics/vite-react-boilerplate/README.md)
for the design, the milestones and the as-built status.

## What is here (the app)

| Surface | Where |
|---|---|
| The app's name, which the heading and the tab's title read | `apps/web/src/site.ts` |
| The welcome page (the template's, but for the heading reading the name), its styles | `apps/web/src/App.tsx`, `apps/web/src/App.css`, `apps/web/src/index.css` |
| The entry and the shell | `apps/web/src/main.tsx`, `apps/web/index.html` |
| The logos | `apps/web/public/vite.svg`, `apps/web/src/assets/react.svg` |
| The build: the React plugin and the title writer; the TypeScript projects | `apps/web/vite.config.ts`, `apps/web/tsconfig*.json` |
| The app's spec (new: the template ships none) | `apps/web/src/App.test.tsx` (Vitest, jsdom), `apps/web/vitest.config.ts` |
| The Worker in front of the assets, its config, deploy contract | `apps/web/worker/index.ts`, `apps/web/wrangler.jsonc`, `apps/web/component.yaml` |
| Tests (the name seam, the build config, the Worker's routing, the template's page) | `tests/web` (vitest) |

## Getting started

```bash
pnpm install
pnpm typecheck # tsc -b: the app, the Vite configs and the Worker
pnpm lint # eslint (the template's config)
pnpm test # vitest: the app's spec and tests/web
pnpm build # tsc -b && vite build → apps/web/dist
```

```bash
pnpm --filter @app/web dev # vite on http://localhost:3000, with HMR
pnpm --filter @app/web preview # wrangler dev over the built app and its Worker
```

## How it maps to Vercel

| Vercel | Here |
|---|---|
| Static output on Vercel's CDN, from its Vite framework preset | Workers Static Assets: `dist` uploaded with the Worker `<repo>-web-<env>` (`apps/web/wrangler.jsonc`) |
| The template's build (`tsc -b && vite build`) | The same command, through turbo, on the template's Vite 5 and React 18 (they build on the runners' Node 22, so nothing moves) |
| No tests | `apps/web/src/App.test.tsx`: the page rendered in jsdom by Vitest with the app's own Vite config — its heading, its logo links, its counter |
| A page address other than `/` answered by the host (the template sets no rewrite) | Every page address is the app's: a browser's navigation that matches no file gets `index.html` (`not_found_handling: single-page-application`), and the Worker hands any other page request back to the assets, so a router the app adds owns every route |
| The host's 404 for a missing file | The Worker answers 404 when the path names a file (`/missing.js`), so a stale script reference fails as a 404, not as HTML parsed as JavaScript |
| The tab's title, written in `index.html` | The site's name, written into `index.html` by `vite.config.ts` from `apps/web/src/site.ts` |
| Deploy on push | Orun deploys `<repo>-web-{stage,prod}` on merge to `main` (`apps/web/component.yaml`) |
| "Deploy with Vercel" (clone the template) | `orun new --blueprint repo-blueprint.yaml` — a new repository, branded, deployed |

## CI

| Workflow | What it runs | Ships to an app |
|---|---|---|
| `ci.yml` | the Orun pipeline, and the only workflow an app carries: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes (the app built and dry-deployed per environment; the tests' `quick-check` lane installs and checks the package, it does not run them), except the bootstrap's own landings (`orun/BASE-*`), where `plan` alone is the check; a merge deploys stage → prod. It plans nothing while `intent.yaml` names the placeholder workspace `ws_CHANGE_ME`, as this repository does. A manual run (Orunbase's Deploy button, or Run workflow on `main`) plans the environment and components it names under the push-to-main trigger, so they deploy as a merge deploys them | yes |

## Credits

The app is Vercel's Vite and React example
([vercel/examples](https://github.com/vercel/examples),
`framework-boilerplates/vite-react`, © 2023 Vercel, MIT — `apps/web/LICENSE.md`),
itself create-vite's React and TypeScript template, at vercel/examples `de86723`.
21 changes: 21 additions & 0 deletions apps/web/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2023 Vercel, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions apps/web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# apps/web — the Vite and React app

A [Vite](https://vitejs.dev) 5 and [React](https://react.dev) 18 app —
create-vite's React and TypeScript welcome page, as Vercel's Vite - React
example (MIT, `LICENSE.md`) ships it — built fully static by Vite and served
as Cloudflare Workers + Static Assets, as a single-page app:

- the welcome page in `src/App.tsx` — the Vite and React logos linking to
their docs, the heading, the counter button and the HMR hint — with its
styles in `src/App.css` and `src/index.css`
- the entry, `src/main.tsx`, mounting the app in StrictMode into
`index.html`'s root element
- a spec of the page (`src/App.test.tsx`: the heading, the logo links, the
counter), run by Vitest in jsdom with the app's own Vite config — the
template ships none

The app's name is in `src/site.ts`; the page's heading reads it, and
`vite.config.ts` writes it into `index.html` as the tab's title.

`worker/index.ts` sits in front of the static build: the assets answer every
file and every browser navigation (`not_found_handling:
"single-page-application"` in `wrangler.jsonc`), and the Worker answers what
is left — a 404 for a path that names a missing file, the app for any other
page.

```bash
pnpm dev # vite on http://localhost:3000, with HMR
pnpm build # tsc -b && vite build → dist
pnpm test # vitest: the page's spec, once, in jsdom
pnpm preview # wrangler dev over the built app, behind worker/index.ts
```

How it is deployed — per environment, on merge to `main` — is the
repository's README and `component.yaml` beside this file.
90 changes: 90 additions & 0 deletions apps/web/component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
apiVersion: sourceplane.io/v1
kind: Component
metadata:
name: web
description: The Vite and React app (Vite 5 and React 18, built fully static and served as Cloudflare Workers + Static Assets behind one Worker with single-page-app routing, per environment)
spec:
type: cloudflare-workers-assets-turbo
lifecycle: production
owner: platform
# Its pages, attached to it in the workspace's catalog: what the Docs
# library shows for it, and what the catalog's docs and runbook checks read.
# Generated from what this manifest and its sources declare.
docs:
overview: docs/overview.md
pages:
- { path: docs/architecture.md, role: architecture, title: Architecture }
- { path: docs/runbook.md, role: runbook, title: Runbook }
# `app`, not `web`: a domain and a component share one name space in the
# catalog, and a domain called `web` hid this component from it.
domain: app
path: apps/web
# Its own lane per environment: the app's build is the longest job in the
# plan, and a shared lane would wait on it.
lane: isolated
subscribe:
environments:
- name: dev
profile: verify
- name: stage
profile: verify
profileRules:
- profile: deploy
when:
triggerRef: github-push-main
- name: prod
profile: verify
profileRules:
- profile: deploy
when:
triggerRef: github-push-main
parameters:
nodeVersion: "22"
pnpmVersion: "10.12.1"

workspaceDir: ../..
appDir: .

turboFilter: "@app/web"
# The config the dry run and the deploy hand to wrangler: the Worker
# (worker/index.ts) and the static build in dist as its assets,
# with single-page-app routing. The app builds fully static, so there is
# no adapter and no generated config — this committed file is the one
# wrangler deploys.
wranglerConfig: wrangler.jsonc

# `vite build` (after `tsc -b`) writes index.html, the hashed JavaScript
# and CSS bundles and the React logo under assets/, and the Vite logo to
# dist.
# The Worker is a source file wrangler bundles at deploy; the lane checks
# it exists after the build like any entry.
workerEntrypoint: worker/index.ts
assetsDir: dist

# Per-env worker name: vite-react-boilerplate-web-{dev,stage,prod}.
workerName: vite-react-boilerplate-web
environmentAwareWorkerName: true

# The account's workers.dev subdomain; exported to the smoke step as
# ${WORKERS_DEV_SUBDOMAIN} and used to build ${DEPLOYED_URL}.
workersDevSubdomain: your-workers-subdomain

installCommand: pnpm install --frozen-lockfile
# The app writes no absolute URL (it renders in the browser, from the
# origin it was loaded from), so the build takes no origin and is the same
# for every environment.
buildCommand: pnpm exec turbo run build --filter=@app/web

# Smoke: the home page is the app's shell (index.html with its root
# <div>), the bundle it loads is served and carries the template's
# counter ("count is" — not the site's name, which is the owner's to
# change), a deep link answers with the same shell (the app renders in
# the browser), and a missing file is a 404 rather than the app's page
# (the Worker's rule). Each response is buffered before grep so an early
# match cannot SIGPIPE curl.
smokeCommand: "html=$(curl -sfL \"${DEPLOYED_URL}/\") && echo \"${html}\" | grep -q '<div id=\"root\"></div>' && main=$(echo \"${html}\" | grep -oE 'assets/index-[A-Za-z0-9_-]+[.]js' | head -n 1) && test -n \"${main}\" && js=$(curl -sfL \"${DEPLOYED_URL}/${main}\") && echo \"${js}\" | grep -q 'count is' && deep=$(curl -sfL \"${DEPLOYED_URL}/some/deep/link\") && echo \"${deep}\" | grep -q '<div id=\"root\"></div>' && test \"$(curl -s -o /dev/null -w '%{http_code}' \"${DEPLOYED_URL}/no-such-file.js\")\" = 404"
labels:
team: platform
layer: delivery
surface: web
runtime: cloudflare
16 changes: 16 additions & 0 deletions apps/web/docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# web — architecture

Built by the turbo pipeline from `apps/web` and deployed with wrangler.

| | |
| ------------------- | ----------------------------------------------- |
| Worker config | `apps/web/wrangler.jsonc` |
| Entry | `./worker/index.ts` |
| Compatibility date | `2026-10-01` |
| Compatibility flags | `nodejs_compat`, `global_fetch_strictly_public` |

## Bindings

| Binding | Kind | Source |
| -------- | ------------- | -------- |
| `ASSETS` | Static assets | `./dist` |
20 changes: 20 additions & 0 deletions apps/web/docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# web

The Vite and React app (Vite 5 and React 18, built fully static and served as Cloudflare Workers + Static Assets behind one Worker with single-page-app routing, per environment)

A Cloudflare Worker with Static Assets (server rendering plus static files), deployed per environment by its CI lane.

| | |
| ------------ | ------------------------------------------------------------------------------------------------------------------ |
| Type | `cloudflare-workers-assets-turbo` |
| Source | `apps/web` |
| Package | `@app/web` |
| Environments | `dev`: `verify` · `stage`: `verify`, `deploy` on a push to `main` · `prod`: `verify`, `deploy` on a push to `main` |

## Depends on

- (none)

## Depended on by

- (none)
38 changes: 38 additions & 0 deletions apps/web/docs/runbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# web — runbook

## How it runs

Pull requests verify it; a merge to `main` deploys it to `stage`, `prod`.
CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`;
the plan orders a component after everything it depends on.

## Local commands

```bash
pnpm --filter @app/web dev
pnpm --filter @app/web build
pnpm --filter @app/web test
pnpm --filter @app/web typecheck
pnpm --filter @app/web lint
pnpm --filter @app/web preview
```

## Verify

After a deploy the lane runs this smoke against the environment it
deployed (`ORUN_ENVIRONMENT`); `DEPLOYED_URL` overrides the URL:

```bash
html=$(curl -sfL "${DEPLOYED_URL}/") && echo "${html}" | grep -q '<div id="root"></div>' && main=$(echo "${html}" | grep -oE 'assets/index-[A-Za-z0-9_-]+[.]js' | head -n 1) && test -n "${main}" && js=$(curl -sfL "${DEPLOYED_URL}/${main}") && echo "${js}" | grep -q 'count is' && deep=$(curl -sfL "${DEPLOYED_URL}/some/deep/link") && echo "${deep}" | grep -q '<div id="root"></div>' && test "$(curl -s -o /dev/null -w '%{http_code}' "${DEPLOYED_URL}/no-such-file.js")" = 404
```

## Rollback

Revert the commit on `main`. The next convergence applies the previous desired
state; nothing was changed out of band, so there is nothing else to undo.

## Common failures

- **The smoke fails right after a first deploy**: a new workers.dev route can
answer 4xx for a few seconds and the lane retries. A failure that persists
is a regression in the deployed code.
28 changes: 28 additions & 0 deletions apps/web/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist', '.wrangler'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions apps/web/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>__SITE_NAME__</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@app/web",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --port 3000",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "wrangler dev",
"test": "vitest run",
"typecheck": "tsc -b"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.1.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^9.9.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"jsdom": "^25.0.1",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.1",
"vite": "^5.4.1",
"vitest": "^3.2.4",
"wrangler": "^4.151.0"
}
}
1 change: 1 addition & 0 deletions apps/web/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.
Loading
Loading