The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 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 Railway: static |
| 31 | * assets (the `vite build` output) served by a generated Node static-file |
| 32 | * server on one `Railway.Service`. For client-only projects — React/Vue/Solid |
| 33 | * SPAs, `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. 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 | * SSR frameworks that wrap Vite deploy through their own composites |
| 46 | * ({@link Astro | Railway.Website.Astro}, {@link SvelteKit | Railway.Website.SvelteKit}, |
| 47 | * {@link Octane | Railway.Website.Octane}, ...) — this composite never |
| 48 | * creates a framework server module. |
| 49 | * |
| 50 | * ### Creating Vite Sites |
| 51 | * **Example:** Basic Vite SPA |
| 52 | * ```typescript |
| 53 | * const site = yield* Railway.Website.Vite("Web"); |
| 54 | * ``` |
| 55 | * |
| 56 | * **Example:** Project in a Subdirectory |
| 57 | * ```typescript |
| 58 | * const site = yield* Railway.Website.Vite("Web", { |
| 59 | * rootDir: "./app", |
| 60 | * }); |
| 61 | * ``` |
| 62 | * |
| 63 | * **Example:** Existing Project |
| 64 | * ```typescript |
| 65 | * const project = yield* Railway.Project("Site"); |
| 66 | * const site = yield* Railway.Website.Vite("Web", { |
| 67 | * project, |
| 68 | * }); |
| 69 | * ``` |
| 70 | * |
| 71 | * ### Custom Domain |
| 72 | * **Example:** Existing hostname |
| 73 | * ```typescript |
| 74 | * // Publish the records in `Railway.CustomDomain.dnsRecords` yourself. |
| 75 | * const site = yield* Railway.Website.Vite("Web", { |
| 76 | * domain: "www.example.com", |
| 77 | * }); |
| 78 | * ``` |
| 79 | * |
| 80 | * **Example:** Publish DNS in Cloudflare |
| 81 | * ```typescript |
| 82 | * // Railway's CNAME and verification TXT are published in the Cloudflare |
| 83 | * // zone. Requires Cloudflare.providers() in the stack. |
| 84 | * const site = yield* Railway.Website.Vite("Web", { |
| 85 | * domain: { name: "www.example.com", dns: Cloudflare.DNS.Adapter() }, |
| 86 | * }); |
| 87 | * ``` |
| 88 | * |
| 89 | * ### Multi-Page Sites |
| 90 | * **Example:** Per-Route HTML Pages with a 404 Page |
| 91 | * ```typescript |
| 92 | * const site = yield* Railway.Website.Vite("Docs", { |
| 93 | * assets: { notFoundHandling: "404-page" }, |
| 94 | * }); |
| 95 | * ``` |
| 96 | * |
| 97 | * ### Build Configuration |
| 98 | * **Example:** Custom Output Directory and Base Path |
| 99 | * ```typescript |
| 100 | * const site = yield* Railway.Website.Vite("Docs", { |
| 101 | * vite: { outDir: "build", base: "/docs/" }, |
| 102 | * }); |
| 103 | * ``` |
| 104 | * |
| 105 | * ### Local Development |
| 106 | * **Example:** Vite Dev Server Under `alchemy dev` |
| 107 | * ```typescript |
| 108 | * // `alchemy dev` starts `vite` programmatically: site.url is the local |
| 109 | * // dev server (HMR included); no Project or Service is created. |
| 110 | * const site = yield* Railway.Website.Vite("Web"); |
| 111 | * ``` |
| 112 | * |
| 113 | * @resource |
| 114 | * @product Website |
| 115 | */ |
| 116 | export const Vite = (id: string, props: ViteProps = {}) => |
| 117 | makeFrameworkSite(id, props, { |
| 118 | name: "Vite", |
| 119 | framework: VITE_FRAMEWORK_SPECIFIER, |
| 120 | target: VITE_NODE_TARGET_SPECIFIER, |
| 121 | options: { |
| 122 | ...viteOptions(props), |
| 123 | notFoundHandling: "spa", |
| 124 | htmlHandling: props.assets?.htmlHandling, |
| 125 | }, |
| 126 | static: staticConfigFromAssets(props.assets, { |
| 127 | notFoundHandling: "single-page-application", |
| 128 | }), |
| 129 | }).pipe(Namespace.push(id)); |