Skip to content
TypeScript
4.0 KB
Raw Blame
---
title: Vinext
description: Deploy vinext to Fly with the shared Website API, native local development, and a platform-specific data cache.
sidebar:
  order: 9.6
---

import PackageManagers from "../../../../components/PackageManagers.astro";

export const devDeps = "@alchemy.run/frontend-frameworks";

`Fly.Website.Vinext` builds with the Vinext Vite API for production and runs native
`vinext dev` locally. The built app runs in a Fly Machine using vinext's production Node server.
Alchemy creates an App when `app` is omitted and deploys a Service containing
`dist/` and vinext's runtime dependencies.

## Install

Keep `vinext`, `react`, `react-dom`, and `react-server-dom-webpack` in your
application dependencies, with `vite` and `@vitejs/plugin-rsc` for building.
Add the Alchemy integration:

<PackageManagers dev={devDeps} />

## Configure vinext

```typescript
// vite.config.ts
import { defineConfig } from "vite";
import vinext from "vinext";

export default defineConfig({
  plugins: [vinext({ prerender: true })],
});
```

Alchemy injects the target-specific data-cache adapter during deployment.
No Alchemy plugin is required in `vite.config.ts`; deployment settings belong on
`Website.Vinext`. Leave Cloudflare plugins and Worker entrypoints out of this application.

## Declare the Website

```typescript
// alchemy.run.ts
import * as Fly from "@alchemy.run/fly";

export const Website = Fly.Website.Vinext("Website", {
  rootDir: ".",
});
```

`rootDir`, `env`, `memo`, `assets`, `dev`, and `domain` use the same vocabulary
as the other Website constructors. Framework configuration stays in
`vite.config.ts` rather than a nested server configuration object.

## Add it to the Stack

```typescript
import * as Alchemy from "alchemy";
import * as Effect from "effect/Effect";

export default Alchemy.Stack(
  "MyVinextSite",
  { providers: Fly.providers(), state: Alchemy.localState() },
  Effect.gen(function* () {
    const site = yield* Website;
    return { url: site.url };
  }),
);
```

Keep the local state available for subsequent deploys and teardown.

## Add environment variables

```typescript
export const Website = Fly.Website.Vinext("Website", {
  env: { GREETING: "Hello from vinext on Fly!" },
});
```

`env` is available during build, development, and production. Server code reads
`process.env`; public framework variables may be compiled into browser assets.
Keep secrets out of public keys and wrap credentials in `Redacted`.

## Read the runtime environment

```typescript
// app/api/hello/route.ts
export function GET(request: Request) {
  const name = new URL(request.url).searchParams.get("name") ?? "world";
  return Response.json({ name, greeting: process.env.GREETING ?? "hello" });
}
```

Request-dependent route handlers read the production environment. A prerendered
page reflects its build-time inputs instead.

## Configure the data cache

The default data cache is process-local. For shared, persistent ISR and
`"use cache"`, pass a `Fly.Redis` resource. Alchemy binds `REDIS_URL` as an App
secret. A separately declared Redis resource retains its own lifecycle in dev.

```typescript
const redis = yield* Fly.Redis("Cache", { eviction: true });
const site = yield* Fly.Website.Vinext("Web", { redis });
```

## Local development

```sh
bun alchemy dev
```

The Website runs `vinext dev` with native HMR and creates no cloud resources.
Other resources declared in the Stack retain their own provider behavior.
Apply `.pipe(Alchemy.remote())` to the Website for a live deployment during dev.

## Custom domains

```typescript
const site = yield* Fly.Website.Vinext("Web", {
  domain: "app.example.com",
});
```

See [Website domains](/fly/frontend/websites) for platform-specific DNS and
certificate configuration.

## Where next

- [vinext API reference](/providers/fly/website/vinext).
- [Runnable example](https://github.com/alchemy-run/alchemy/tree/main/examples/fly-website-vinext).
- [Website overview](/fly/frontend/websites).
- [vinext on Cloudflare](/cloudflare/frontend/vinext) and [Prisma](/prisma/frontend/vinext).