Nuxt
Archil.Website.Nuxt deploys a Nuxt app to an Archil
sandbox, through nitro’s Node server; prerendered pages are served first. The site is the
program of its own sandbox, on port 3000, at a public
https://3000-…archil.app URL. A stopped sandbox starts again on the next
request.
Install
Section titled “Install”The build integration is not bundled with alchemy. Install
@alchemy.run/frontend-frameworks; the resource loads its /nuxt
and /nuxt/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/pr:2930:0cabab6bun add -d https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/pr:2930:0cabab6npm install -D https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/pr:2930:0cabab6yarn add -D https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/pr:2930:0cabab6Configure Nuxt
Section titled “Configure Nuxt”Your nuxt.config.ts loads natively — modules, layers, and all —
so configure Nuxt exactly as you would outside Alchemy:
export default defineNuxtConfig({ modules: ["@nuxtjs/tailwindcss"], routeRules: { "/about": { prerender: true }, },});Deploy-specific overrides are merged over it via the nuxt prop
(the override wins) — see Prerendering below for an
example.
Don’t set nitro.preset — the Node deploy target owns the preset
("node"), and a foreign preset is a hard error.
Declare the Website
Section titled “Declare the Website”Declare the site as a module-level const:
import * as Archil from "@alchemy.run/archil";
export const Website = Archil.Website.Nuxt("Website");sandbox sizes the site’s sandbox and sets its image, timeouts, disks and network policy:
export const Website = Archil.Website.Nuxt("Website", { sandbox: { vcpuCount: 2, memSizeMiB: 4096, idleTtlSeconds: 600 },});Add it to the Stack
Section titled “Add it to the Stack”Yield the site from your Stack and return its URL:
import * as Archil from "@alchemy.run/archil";import * as Alchemy from "alchemy";import * as Effect from "effect/Effect";
export const Website = Archil.Website.Nuxt("Website");
export default Alchemy.Stack( "MyNuxtSite", { providers: Archil.providers(), state: Alchemy.localState(), }, Effect.gen(function* () { const site = yield* Website; return { url: site.url }; }),);Run alchemy deploy. url is the site’s https://3000-…archil.app URL.
site.sandbox is the sandbox behind it, and undefined under
alchemy dev.
See examples/archil-website-nuxt for the checked-in example.
Add environment variables
Section titled “Add environment variables”Process environment is the top-level env prop — plain strings, or
Redacted values. They are copied onto process.env before build
and alchemy dev, and onto the program at deploy:
export const Website = Archil.Website.Nuxt("Website", { env: { GREETING: "Hello from Alchemy!", NUXT_PUBLIC_API_BASE: "https://api.example.com", },});This is the hosted Node process, not Worker bindings.
NUXT_-prefixed keys override Nuxt runtimeConfig the usual way;
NUXT_PUBLIC_ values are inlined into the client at build time.
Read the environment in server code
Section titled “Read the environment in server code”The nitro server is a plain Node process, so server routes and SSR
read the environment from process.env:
export default defineEventHandler(() => { return { greeting: process.env.GREETING ?? "hello" };});Prerendering
Section titled “Prerendering”Routes marked for prerendering in routeRules (or via
nitro.prerender) render at build time into .output/public and
are uploaded with the program, served as static files before the nitro
handler:
export const Website = Archil.Website.Nuxt("Website", { nuxt: { routeRules: { "/about": { prerender: true }, }, },});Nitro’s isr route rule is implemented only by the Vercel and
Netlify presets. On the Node preset it is silently ignored at build
time, and the route renders on demand like any other SSR route. Use
prerender for build-time static routes, or cache route rules for
runtime caching.
Local dev
Section titled “Local dev”bun alchemy devalchemy dev runs Nuxt’s own dev server (nitro dev, full HMR)
instead of deploying; site.url is the local address and no
Archil resources are created. Wrap the site in Alchemy.remote()
to deploy the live sandbox even during dev.
Where next
Section titled “Where next”Archil.Website.Nuxtreference- Websites — every framework Archil hosts
- Programs and Sandboxes — what the site runs on