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

main
ts 121 lines 3.85 KB
Raw
1 import { frameworkSite, staticConfigFromAssets, type FrameworkSiteProps } from "./FrameworkSite.ts";
2
3 /** The framework-integration package that drives the Vite build. */
4 export const VITE_FRAMEWORK_SPECIFIER = "@alchemy.run/frontend-frameworks/vite";
5
6 /** The Node container deploy target for the Vite build. */
7 export const VITE_NODE_TARGET_SPECIFIER = "@alchemy.run/frontend-frameworks/vite/node";
8
9 const viteOptions = (props: ViteProps) =>
10 props.vite !== undefined && (props.vite.outDir !== undefined || props.vite.base !== undefined)
11 ? { vite: props.vite }
12 : undefined;
13
14 export interface ViteProps extends FrameworkSiteProps {
15 /**
16 * Serializable Vite config merged OVER the project's own `vite.config.*`
17 * (which loads natively, plugins included).
18 */
19 vite?: {
20 /**
21 * Build output directory, relative to `rootDir`.
22 * @default the project config's `build.outDir` (vite's default: "dist")
23 */
24 outDir?: string;
25 /** Public base path the site deploys under (vite's `base`). */
26 base?: string;
27 };
28 }
29
30 /**
31 * Deploy a plain [Vite](https://vite.dev) application to Fly: a Service
32 * serving the `vite build` output from a tiny static-file server. For
33 * client-only projects — React/Vue/Solid SPAs, `index.html` multi-page
34 * apps — whose entire deployable output is 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. Your project's own `vite.config.*`
39 * (plugins included) drives the build.
40 *
41 * During `alchemy dev` the site is Vite's own dev server (native HMR) and
42 * no cloud resources are created — the site's `url` is the dev server's
43 * local address. `Alchemy.remote()` opts back into the full deployment.
44 *
45 *
46 * ### Creating Vite Sites
47 * **Example:** Basic Vite SPA
48 * ```typescript
49 * const site = yield* Fly.Website.Vite("Web");
50 * ```
51 *
52 * **Example:** Project in a Subdirectory
53 * ```typescript
54 * const site = yield* Fly.Website.Vite("Web", {
55 * rootDir: "./app",
56 * });
57 * ```
58 *
59 * **Example:** Existing App
60 * ```typescript
61 * const site = yield* Fly.Website.Vite("Web", { app: Site });
62 * ```
63 *
64 * ### Multi-Page Sites
65 * **Example:** Per-Route HTML Pages with a 404 Page
66 * ```typescript
67 * const site = yield* Fly.Website.Vite("Docs", {
68 * assets: { notFoundHandling: "404-page" },
69 * });
70 * ```
71 *
72 * ### Custom Domain
73 * **Example:** ACME on an existing hostname
74 * ```typescript
75 * const site = yield* Fly.Website.Vite("Web", {
76 * domain: "app.example.com",
77 * });
78 * ```
79 *
80 * **Example:** Publish DNS in Cloudflare
81 * ```typescript
82 * // The ACME challenge CNAME and A/AAAA records are published in the
83 * // Cloudflare zone. Requires Cloudflare.providers() in the stack.
84 * const site = yield* Fly.Website.Vite("Web", {
85 * domain: { name: "app.example.com", dns: Cloudflare.DNS.Adapter() },
86 * });
87 * ```
88 *
89 * ### Build Configuration
90 * **Example:** Custom Output Directory and Base Path
91 * ```typescript
92 * const site = yield* Fly.Website.Vite("Docs", {
93 * vite: { outDir: "build", base: "/docs/" },
94 * });
95 * ```
96 *
97 * ### Local Development
98 * **Example:** Vite Dev Server Under `alchemy dev`
99 * ```typescript
100 * // `alchemy dev` starts `vite` programmatically: site.url is the local
101 * // dev server (HMR included); no Fly App or Service is created.
102 * const site = yield* Fly.Website.Vite("Web");
103 * ```
104 *
105 * @resource
106 * @product Website
107 */
108 export const Vite = (id: string, props: ViteProps = {}) =>
109 frameworkSite(id, props, {
110 name: "Vite",
111 framework: VITE_FRAMEWORK_SPECIFIER,
112 target: VITE_NODE_TARGET_SPECIFIER,
113 options: {
114 ...viteOptions(props),
115 notFoundHandling: "spa",
116 htmlHandling: props.assets?.htmlHandling,
117 },
118 static: staticConfigFromAssets(props.assets, {
119 notFoundHandling: "single-page-application",
120 }),
121 });