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

main
ts 124 lines 3.65 KB
Raw
1 import * as Namespace from "alchemy/Namespace";
2 import {
3 makeFrameworkSite,
4 staticConfigFromAssets,
5 type FrameworkSiteProps,
6 } from "./FrameworkSite.ts";
7
8 /** The framework-integration package that drives the Vite build. */
9 export const VITE_FRAMEWORK_SPECIFIER = "@alchemy.run/frontend-frameworks/vite";
10
11 /** The Node container deploy target for the Vite build. */
12 export const VITE_NODE_TARGET_SPECIFIER = "@alchemy.run/frontend-frameworks/vite/node";
13
14 const viteOptions = (props: ViteProps) =>
15 props.vite !== undefined && (props.vite.outDir !== undefined || props.vite.base !== undefined)
16 ? { vite: props.vite }
17 : undefined;
18
19 export interface ViteProps extends FrameworkSiteProps {
20 /**
21 * Serializable Vite config merged OVER the project's own `vite.config.*`.
22 */
23 vite?: {
24 outDir?: string;
25 base?: string;
26 };
27 }
28
29 /**
30 * Deploy a plain [Vite](https://vite.dev) application to a Hetzner Cloud
31 * Server: `vite build` output served by a static-file systemd unit on
32 * port 3000. For client-only projects — React/Vue/Solid SPAs,
33 * `index.html` multi-page apps — whose entire deployable output is
34 * static assets.
35 *
36 * The build runs through `@alchemy.run/frontend-frameworks/vite` with the
37 * `@alchemy.run/frontend-frameworks/vite/node` deploy target — the package
38 * must be installed in your project. During `alchemy dev` the site is
39 * Vite's own dev server and no cloud resources are created.
40 *
41 *
42 * ### Creating Vite Sites
43 * **Example:** Basic Vite SPA
44 * ```typescript
45 * const site = yield* Hetzner.Website.Vite("Web");
46 * ```
47 *
48 * **Example:** Project in a Subdirectory
49 * ```typescript
50 * const site = yield* Hetzner.Website.Vite("Web", {
51 * rootDir: "./app",
52 * });
53 * ```
54 *
55 * **Example:** Existing Server
56 * ```typescript
57 * const server = yield* Hetzner.Server("box", {
58 * serverType: "cpx12",
59 * image: "ubuntu-24.04",
60 * location: "fsn1",
61 * });
62 * const site = yield* Hetzner.Website.Vite("Web", { server });
63 * ```
64 *
65 * ### Multi-Page Sites
66 * **Example:** Per-Route HTML Pages with a 404 Page
67 * ```typescript
68 * const site = yield* Hetzner.Website.Vite("Docs", {
69 * assets: { notFoundHandling: "404-page" },
70 * });
71 * ```
72 *
73 * ### Custom Domain
74 * **Example:** A Record on an Existing Zone
75 * ```typescript
76 * const site = yield* Hetzner.Website.Vite("Web", {
77 * domain: "app.example.com",
78 * zone,
79 * });
80 * ```
81 *
82 * **Example:** Publish DNS in Cloudflare
83 * ```typescript
84 * // No Hetzner zone needed: the A record is published in the Cloudflare
85 * // zone. Requires Cloudflare.providers() in the stack.
86 * const site = yield* Hetzner.Website.Vite("Web", {
87 * domain: { name: "app.example.com", dns: Cloudflare.DNS.Adapter() },
88 * });
89 * ```
90 *
91 * ### Build Configuration
92 * **Example:** Custom Output Directory and Base Path
93 * ```typescript
94 * const site = yield* Hetzner.Website.Vite("Docs", {
95 * outDir: "build",
96 * base: "/docs/",
97 * });
98 * ```
99 *
100 * ### Local Development
101 * **Example:** Vite Dev Server Under `alchemy dev`
102 * ```typescript
103 * // `alchemy dev` starts `vite` programmatically: site.url is the local
104 * // dev server (HMR included); no Server or Service is created.
105 * const site = yield* Hetzner.Website.Vite("Web");
106 * ```
107 *
108 * @resource
109 * @product Website
110 */
111 export const Vite = (id: string, props: ViteProps = {}) =>
112 makeFrameworkSite(id, props, {
113 name: "Vite",
114 framework: VITE_FRAMEWORK_SPECIFIER,
115 target: VITE_NODE_TARGET_SPECIFIER,
116 options: {
117 ...viteOptions(props),
118 notFoundHandling: "spa",
119 htmlHandling: props.assets?.htmlHandling,
120 },
121 static: staticConfigFromAssets(props.assets, {
122 notFoundHandling: "single-page-application",
123 }),
124 }).pipe(Namespace.push(id));