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

main
ts 108 lines 3.47 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 Cloud Run: 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* GCP.Website.Vite("Web");
50 * ```
51 *
52 * **Example:** Project in a Subdirectory
53 * ```typescript
54 * const site = yield* GCP.Website.Vite("Web", {
55 * rootDir: "./app",
56 * });
57 * ```
58 *
59 * ### Multi-Page Sites
60 * **Example:** Per-Route HTML Pages with a 404 Page
61 * ```typescript
62 * const site = yield* GCP.Website.Vite("Docs", {
63 * assets: { notFoundHandling: "404-page" },
64 * });
65 * ```
66 *
67 * ### Cloud Run Settings
68 * **Example:** Warm Instance with More Memory
69 * ```typescript
70 * const site = yield* GCP.Website.Vite("Web", {
71 * scaling: { minInstanceCount: 1 },
72 * resources: { limits: { cpu: "1", memory: "1Gi" } },
73 * });
74 * ```
75 *
76 * ### Build Configuration
77 * **Example:** Custom Output Directory and Base Path
78 * ```typescript
79 * const site = yield* GCP.Website.Vite("Docs", {
80 * vite: { outDir: "build", base: "/docs/" },
81 * });
82 * ```
83 *
84 * ### Local Development
85 * **Example:** Vite Dev Server Under `alchemy dev`
86 * ```typescript
87 * // `alchemy dev` starts `vite` programmatically: site.url is the local
88 * // dev server (HMR included); no Cloud Run service is created.
89 * const site = yield* GCP.Website.Vite("Web");
90 * ```
91 *
92 * @resource
93 * @product Website
94 */
95 export const Vite = (id: string, props: ViteProps = {}) =>
96 frameworkSite(id, props, {
97 name: "Vite",
98 framework: VITE_FRAMEWORK_SPECIFIER,
99 target: VITE_NODE_TARGET_SPECIFIER,
100 options: {
101 ...viteOptions(props),
102 notFoundHandling: "spa",
103 htmlHandling: props.assets?.htmlHandling,
104 },
105 static: staticConfigFromAssets(props.assets, {
106 notFoundHandling: "single-page-application",
107 }),
108 });