Effect UI
DigitalOcean.Website.EffectUI deploys an Effect UI project to App Platform. Deploy builds it on your machine, puts the output in one image, and the App serves its pages, assets and server handler.
Install
Section titled “Install”The build integration is not bundled with alchemy. Install
@alchemy.run/frontend-frameworks; the resource loads its /effect-ui
and /effect-ui/node exports from your project at deploy time. It is only
used at build time, so a dev dependency is enough:
pnpm add -D https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/9c58f00bun add -d https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/9c58f00npm install -D https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/9c58f00yarn add -D https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/9c58f00Effect UI is in public preview and isn’t on npm yet. Install a snapshot
build of @effect/ui as its
README describes.
Configure Vite
Section titled “Configure Vite”A browser-only app needs no plugin. Its Vite config stays what the Effect UI quick start gives you, and the build deploys as static files.
Render pages on the server
Section titled “Render pages on the server”Add HtmlServerVite.plugin and point it at a server entry. With
serverOutDir, the build also emits a request handler, which answers
every request that matches no file:
import { plugin as htmlServer } from "@effect/ui/html/HtmlServerVite";import { defineConfig } from "vite";
export default defineConfig({ build: { outDir: "dist/client" }, plugins: [ htmlServer({ entry: "/src/entry.server.ts", serverOutDir: "dist/server", }), ],});The server output must not overlap the client’s, so the client builds
to dist/client.
The server entry’s default export is a Layer that adds the app’s routes
to HttpRouter. prerender lists the pages the build renders ahead of
time. They are served as files, and the server renders everything else:
/// <reference types="@effect/ui/html/HtmlServerViteDocument" />import { layerHttp } from "@effect/ui/html/HtmlServerHttp";import { document } from "virtual:@effect/ui/document";import { App } from "./App.ts";import { AppRoute } from "./routes.ts";
export default layerHttp(App, { routes: AppRoute, document });
export const prerender = ["/about", "/404"];index.html marks where the page goes with <!--app-html-->. The
browser entry hydrates the server’s HTML instead of mounting a new app:
import { Router } from "@effect/ui";import { BrowserRouter, HtmlHydrate } from "@effect/ui/html";import { Effect, Layer } from "effect";import { App } from "./App.ts";import { AppRoute } from "./routes.ts";
const Main = HtmlHydrate.hydrate( App, Router.props(AppRoute), document.getElementById("app")!, JSON.parse(document.getElementById("state")!.textContent!),).pipe(Layer.provide(BrowserRouter.layer({ routes: AppRoute })));
Layer.launch(Main).pipe(Effect.runFork);Prerender without a server
Section titled “Prerender without a server”Leave serverOutDir out and the build keeps only the prerendered pages.
The site deploys as static files, and a prerendered /404 is the page
for paths that match nothing:
import { plugin as htmlServer } from "@effect/ui/html/HtmlServerVite";import { defineConfig } from "vite";
export default defineConfig({ plugins: [htmlServer({ entry: "/src/entry.server.ts" })],});Declare the site
Section titled “Declare the site”import * as DigitalOcean from "@alchemy.run/digitalocean";import * as Alchemy from "alchemy";import * as Effect from "effect/Effect";
export const Website = DigitalOcean.Website.EffectUI("Website", { rootDir: "./web" });
export default Alchemy.Stack( "MySite", { providers: DigitalOcean.providers(), state: Alchemy.localState() }, Effect.gen(function* () { const site = yield* Website; return { url: site.url }; }),);rootDir is the directory with the project’s package.json. site.url is the App’s HTTPS address. Deploy needs Docker and the team’s Container Registry, or a registry you declare.
Add environment variables
Section titled “Add environment variables”export const Website = DigitalOcean.Website.EffectUI("Website", { rootDir: "./web", env: { VITE_GREETING: "Hello from DigitalOcean" },});env is set before the build and on the App, so build-time and run-time code see the same values. Server code reads process.env; Vite inlines VITE_* keys into the browser build.
Size the App
Section titled “Size the App”region, instanceSizeSlug and instanceCount are passed to the App. See Websites.
Local dev
Section titled “Local dev”alchemy dev runs the project’s Vite dev server with the same env instead of deploying, and site.url is its local address. HtmlServerVite renders every page there.
Where next
Section titled “Where next”DigitalOcean.Website.EffectUIreference: every prop.- Websites: what every site on DigitalOcean shares.
- App Platform: the App the site runs on.