The best way to control Claude Code, Codex and more from any computer or phone

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