Skip to content

Vite

GCP.Website.Vite deploys a client-only Vite app to Cloud Run: a React, Vue, or Solid SPA, or a multi-page index.html site. Alchemy runs vite build with your own vite.config.* and serves the output from a small file server.

Terminal window
pnpm add -D https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/a870ed4

Docker has to be running when you deploy.

alchemy.run.ts
import * as Alchemy from "alchemy";
import * as GCP from "@alchemy.run/gcp";
import * as Effect from "effect/Effect";
export const Website = GCP.Website.Vite("Website");
export default Alchemy.Stack(
"MySite",
{ providers: GCP.providers(), state: GCP.state() },
Effect.gen(function* () {
const site = yield* Website;
return { url: site.url };
}),
);

Unknown paths answer with index.html, so a client-side route like /settings loads the app. For a multi-page site, serve your 404.html instead:

export const Website = GCP.Website.Vite("Docs", {
assets: { notFoundHandling: "404-page" },
});

VITE_* values are inlined into the bundle at build time. Pass a service’s URL through env:

Effect.gen(function* () {
const api = yield* Api;
const site = yield* GCP.Website.Vite("Website", {
env: { VITE_API_URL: api.uri },
});
return { url: site.url };
}),

The browser code reads import.meta.env.VITE_API_URL.

export const Website = GCP.Website.Vite("Docs", {
vite: { outDir: "build", base: "/docs/" },
});
export const Website = GCP.Website.Vite("Website", { rootDir: "./app" });

alchemy dev runs Vite’s dev server with hot reload and creates nothing in the cloud.