The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | --- |
| 2 | title: Vite |
| 3 | description: Deploy any client-only Vite app to Cloud Run with GCP.Website.Vite — your own vite.config, a small static file server, and Vite's dev server under alchemy dev. |
| 4 | sidebar: |
| 5 | order: 2 |
| 6 | --- |
| 7 | |
| 8 | import PackageManagers from "../../../../components/PackageManagers.astro"; |
| 9 | |
| 10 | export const devDeps = "@alchemy.run/frontend-frameworks"; |
| 11 | |
| 12 | `GCP.Website.Vite` deploys a client-only [Vite](https://vite.dev) app |
| 13 | to Cloud Run: a React, Vue, or Solid SPA, or a multi-page `index.html` |
| 14 | site. Alchemy runs `vite build` with your own `vite.config.*` and |
| 15 | serves the output from a small file server. |
| 16 | |
| 17 | ## Install |
| 18 | |
| 19 | <PackageManagers dev={devDeps} /> |
| 20 | |
| 21 | Docker has to be running when you deploy. |
| 22 | |
| 23 | ## Deploy the site |
| 24 | |
| 25 | ```typescript |
| 26 | // alchemy.run.ts |
| 27 | import * as Alchemy from "alchemy"; |
| 28 | import * as GCP from "@alchemy.run/gcp"; |
| 29 | import * as Effect from "effect/Effect"; |
| 30 | |
| 31 | export const Website = GCP.Website.Vite("Website"); |
| 32 | |
| 33 | export default Alchemy.Stack( |
| 34 | "MySite", |
| 35 | { providers: GCP.providers(), state: GCP.state() }, |
| 36 | Effect.gen(function* () { |
| 37 | const site = yield* Website; |
| 38 | return { url: site.url }; |
| 39 | }), |
| 40 | ); |
| 41 | ``` |
| 42 | |
| 43 | ## Deep links |
| 44 | |
| 45 | Unknown paths answer with `index.html`, so a client-side route like |
| 46 | `/settings` loads the app. For a multi-page site, serve your |
| 47 | `404.html` instead: |
| 48 | |
| 49 | ```typescript |
| 50 | export const Website = GCP.Website.Vite("Docs", { |
| 51 | assets: { notFoundHandling: "404-page" }, |
| 52 | }); |
| 53 | ``` |
| 54 | |
| 55 | ## Point the app at an API |
| 56 | |
| 57 | `VITE_*` values are inlined into the bundle at build time. Pass a |
| 58 | service's URL through `env`: |
| 59 | |
| 60 | ```typescript |
| 61 | Effect.gen(function* () { |
| 62 | const api = yield* Api; |
| 63 | const site = yield* GCP.Website.Vite("Website", { |
| 64 | env: { VITE_API_URL: api.uri }, |
| 65 | }); |
| 66 | return { url: site.url }; |
| 67 | }), |
| 68 | ``` |
| 69 | |
| 70 | The browser code reads `import.meta.env.VITE_API_URL`. |
| 71 | |
| 72 | ## Change the output or base path |
| 73 | |
| 74 | ```typescript |
| 75 | export const Website = GCP.Website.Vite("Docs", { |
| 76 | vite: { outDir: "build", base: "/docs/" }, |
| 77 | }); |
| 78 | ``` |
| 79 | |
| 80 | ## Project in a subdirectory |
| 81 | |
| 82 | ```typescript |
| 83 | export const Website = GCP.Website.Vite("Website", { rootDir: "./app" }); |
| 84 | ``` |
| 85 | |
| 86 | ## Local development |
| 87 | |
| 88 | `alchemy dev` runs Vite's dev server with hot reload and creates |
| 89 | nothing in the cloud. |
| 90 | |
| 91 | ## Where next |
| 92 | |
| 93 | - [React SPA](/gcp/frontend/vite-spa) and [Vue](/gcp/frontend/vue) — |
| 94 | framework walkthroughs on the same resource. |
| 95 | - [Website reference](/providers/gcp/website#vite) — every prop. |