| 1 | --- |
| 2 | title: Vinext |
| 3 | description: Deploy vinext to AWS with the shared Website API, native local development, and a platform-specific data cache. |
| 4 | sidebar: |
| 5 | order: 9.6 |
| 6 | --- |
| 7 | |
| 8 | import { Code, Tabs, TabItem } from "@astrojs/starlight/components"; |
| 9 | |
| 10 | export const devDeps = "@alchemy.run/frontend-frameworks"; |
| 11 | |
| 12 | `AWS.Website.Vinext` builds with the Vinext Vite API for production and runs native |
| 13 | `vinext dev` locally. The React Server Components handler runs on a streaming Lambda Function URL. |
| 14 | S3 stores assets and CloudFront routes asset requests to S3 and other requests |
| 15 | to Lambda. This uses vinext, not OpenNext. |
| 16 | |
| 17 | The Lambda target supports **App Router** applications. Use a Node deployment |
| 18 | target such as [Prisma](/prisma/frontend/vinext) or [Fly](/fly/frontend/vinext) |
| 19 | for Pages Router applications. |
| 20 | |
| 21 | ## Install |
| 22 | |
| 23 | Keep `vinext`, `react`, `react-dom`, and `react-server-dom-webpack` in your |
| 24 | application dependencies, with `vite` and `@vitejs/plugin-rsc` for building. |
| 25 | Use vinext **1.0.0-beta.10 or newer**. Alchemy uses its standalone packaging |
| 26 | to include external runtime dependencies in the Lambda archive. Add the Alchemy integration: |
| 27 | |
| 28 | <Tabs syncKey="pkgManager"> |
| 29 | <TabItem label="bun" icon="bun"><Code code={`bun add -d ${devDeps}`} lang="sh" /></TabItem> |
| 30 | <TabItem label="npm" icon="npm"><Code code={`npm install -D ${devDeps}`} lang="sh" /></TabItem> |
| 31 | <TabItem label="pnpm" icon="pnpm"><Code code={`pnpm add -D ${devDeps}`} lang="sh" /></TabItem> |
| 32 | <TabItem label="yarn" icon="seti:yarn"><Code code={`yarn add -D ${devDeps}`} lang="sh" /></TabItem> |
| 33 | </Tabs> |
| 34 | |
| 35 | ## Configure vinext |
| 36 | |
| 37 | ```typescript |
| 38 | // vite.config.ts |
| 39 | import { defineConfig } from "vite"; |
| 40 | import vinext from "vinext"; |
| 41 | |
| 42 | export default defineConfig({ |
| 43 | plugins: [vinext({ prerender: true })], |
| 44 | }); |
| 45 | ``` |
| 46 | |
| 47 | Alchemy injects the target-specific data-cache adapter during deployment. |
| 48 | No Alchemy plugin is required in `vite.config.ts`; deployment settings belong on |
| 49 | `Website.Vinext`. Leave Cloudflare plugins and Worker entrypoints out of this application. |
| 50 | |
| 51 | ## Declare the Website |
| 52 | |
| 53 | ```typescript |
| 54 | // alchemy.run.ts |
| 55 | import * as AWS from "alchemy/AWS"; |
| 56 | |
| 57 | export const Website = AWS.Website.Vinext("Website", { |
| 58 | rootDir: ".", |
| 59 | }); |
| 60 | ``` |
| 61 | |
| 62 | `rootDir`, `env`, `memo`, `assets`, `dev`, and `domain` use the same vocabulary |
| 63 | as the other Website constructors. Framework configuration stays in |
| 64 | `vite.config.ts` rather than a nested server configuration object. |
| 65 | |
| 66 | ## Add it to the Stack |
| 67 | |
| 68 | ```typescript |
| 69 | import * as Alchemy from "alchemy"; |
| 70 | import * as Effect from "effect/Effect"; |
| 71 | |
| 72 | export default Alchemy.Stack( |
| 73 | "MyVinextSite", |
| 74 | { providers: AWS.providers(), state: Alchemy.localState() }, |
| 75 | Effect.gen(function* () { |
| 76 | const site = yield* Website; |
| 77 | return { url: site.url }; |
| 78 | }), |
| 79 | ); |
| 80 | ``` |
| 81 | |
| 82 | Keep the local state available for subsequent deploys and teardown. |
| 83 | |
| 84 | ## Add environment variables |
| 85 | |
| 86 | ```typescript |
| 87 | export const Website = AWS.Website.Vinext("Website", { |
| 88 | env: { GREETING: "Hello from vinext on AWS!" }, |
| 89 | }); |
| 90 | ``` |
| 91 | |
| 92 | `env` is available during build, development, and production. Server code reads |
| 93 | `process.env`; public framework variables may be compiled into browser assets. |
| 94 | Keep secrets out of public keys and wrap credentials in `Redacted`. |
| 95 | |
| 96 | ## Read the runtime environment |
| 97 | |
| 98 | ```typescript |
| 99 | // app/api/hello/route.ts |
| 100 | export function GET(request: Request) { |
| 101 | const name = new URL(request.url).searchParams.get("name") ?? "world"; |
| 102 | return Response.json({ name, greeting: process.env.GREETING ?? "hello" }); |
| 103 | } |
| 104 | ``` |
| 105 | |
| 106 | Request-dependent route handlers read the production environment. A prerendered |
| 107 | page reflects its build-time inputs instead. |
| 108 | |
| 109 | ## Configure the data cache |
| 110 | |
| 111 | The Website provisions an S3 bucket for ISR and `"use cache"`, sets |
| 112 | `CACHE_BUCKET_NAME`, and grants the Lambda access. The build selects the S3 |
| 113 | adapter. Local development uses memory and creates no bucket. |
| 114 | |
| 115 | ## Local development |
| 116 | |
| 117 | ```sh |
| 118 | bun alchemy dev |
| 119 | ``` |
| 120 | |
| 121 | The Website runs `vinext dev` with native HMR and creates no cloud resources. |
| 122 | Other resources declared in the Stack retain their own provider behavior. |
| 123 | Apply `.pipe(Alchemy.remote())` to the Website for a live deployment during dev. |
| 124 | |
| 125 | ## Custom domains |
| 126 | |
| 127 | ```typescript |
| 128 | const site = yield* AWS.Website.Vinext("Web", { |
| 129 | domain: "app.example.com", |
| 130 | }); |
| 131 | ``` |
| 132 | |
| 133 | See [Website domains](/aws/frontend/websites) for platform-specific DNS and |
| 134 | certificate configuration. |
| 135 | |
| 136 | ## Where next |
| 137 | |
| 138 | - [vinext API reference](/providers/aws/website/vinext). |
| 139 | - [Runnable example](https://github.com/alchemy-run/alchemy/tree/main/examples/aws-website-vinext). |
| 140 | - [Website overview](/aws/frontend/websites). |
| 141 | - [vinext on Cloudflare](/cloudflare/frontend/vinext) and [Prisma](/prisma/frontend/vinext). |