vite.config.ts
This file
Path
apps/web/vite.config.ts
100 lines · 3.4 KiB · TypeScript
Last changed by
Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge perf/ssr-highlight into mainoscabrielbefore adoption5881ff2
lines 1–2why, one step back1import { fileURLToPath } from "node:url";2Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 3–6why, one step back3import { cloudflare } from "@cloudflare/vite-plugin";4import tailwindcss from "@tailwindcss/vite";5import { tanstackStart } from "@tanstack/react-start/plugin/vite";6import viteReact from "@vitejs/plugin-react";Merge chore/web-dev-host into mainoscabrielbefore adoption4a9b05a
lines 7–8why, one step back7import { defineConfig, loadEnv } from "vite";8import type { Plugin, ServerOptions } from "vite";Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 9–14why, one step back910import {11 MANIFEST_PATH,12 webManifestText,13} from "./src/features/agents/manifest.ts";14Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248
line 15why, one step back15// Made from `Brand.name` rather than kept as a file that would spell the name.Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 16–34why, one step back16const webAppManifest = (): Plugin => ({17 configureServer: (server) => {18 server.middlewares.use(MANIFEST_PATH, (_request, response) => {19 response.setHeader("content-type", "application/manifest+json");20 response.end(webManifestText());21 });22 },23 generateBundle() {24 if (this.environment.name === "client") {25 this.emitFile({26 fileName: MANIFEST_PATH.slice(1),27 source: webManifestText(),28 type: "asset",29 });30 }31 },32 name: "web-app-manifest",33});34Merge perf/ssr-highlight into mainoscabrielbefore adoption5881ff2
lines 35–41why, one step back35const NO_WASM = "\0worker-no-shiki-wasm";3637const WORKER_IN_PLACE = new Map([38 ["@pierre/theming/themes", "src/server/pierre-themes.ts"],39 ["shiki", "src/server/shiki.ts"],40]);41Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248
lines 42–43why, one step back42// The Worker's Shiki: core and the JavaScript engine alone, with no theme collection, so the server bundles only43// the grammars it names, never Shiki's 10 MB map, Pierre's themes or WebAssembly. The browser keeps the whole packages.Merge perf/ssr-highlight into mainoscabrielbefore adoption5881ff2
lines 44–59why, one step back44const workerShiki = (): Plugin => ({45 applyToEnvironment: (environment) => environment.name === "ssr",46 enforce: "pre",47 load: (id) => (id === NO_WASM ? "export default undefined;" : undefined),48 name: "worker-shiki",49 resolveId: (id) => {50 const inPlace = WORKER_IN_PLACE.get(id);5152 if (inPlace !== undefined) {53 return fileURLToPath(new URL(inPlace, import.meta.url));54 }5556 return id === "shiki/wasm" ? NO_WASM : undefined;57 },58});59Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 60–62why, one step back60// The Cloudflare framework guide's order: the Worker runs TanStack Start's61// SSR environment, and Start comes before React. `vite build` picks the62// stage from `CLOUDFLARE_ENV` (infra/deploy.ts sets it).Merge chore/web-dev-host into mainoscabrielbefore adoption4a9b05a
lines 63–64why, one step back63export default defineConfig(({ mode }) => {64 // This machine's Caddy name for the dev server, from the gitignoredMerge perf/minify-web into mainoscabrielbefore adoption260fd43
lines 65–67why, one step back65 // `apps/web/.env.development.local`, which Vite reads in dev and Wrangler66 // never loads as a Worker secret; without one, the dev server answers on67 // 127.0.0.1 alone.Merge chore/web-dev-host into mainoscabrielbefore adoption4a9b05a
lines 68–87why, one step back68 const caddyDevHost = loadEnv(mode, process.cwd(), "").CADDY_DEV_HOST;6970 const server: ServerOptions = {71 host: "127.0.0.1",72 port: 3032,73 strictPort: true,74 };7576 if (caddyDevHost !== undefined && caddyDevHost !== "") {77 server.allowedHosts = ["localhost", "127.0.0.1", caddyDevHost];78 server.hmr = { clientPort: 443, host: caddyDevHost, protocol: "wss" };79 }8081 return {82 plugins: [83 cloudflare({ viteEnvironment: { name: "ssr" } }),84 tailwindcss(),85 tanstackStart(),86 viteReact(),87 webAppManifest(),Merge perf/ssr-highlight into mainoscabrielbefore adoption5881ff2
line 88why, one step back88 workerShiki(),Merge chore/web-dev-host into mainoscabrielbefore adoption4a9b05a
lines 89–93why, one step back89 ],90 // shadcn's components import through `@/` (components.json), which91 // tsconfig.json's `paths` maps to `src/`.92 resolve: { tsconfigPaths: true },93 server,Merge perf/minify-web into mainoscabrielbefore adoption260fd43
lines 94–98why, one step back94 // The Worker's own code is minified like the browser's: about a third95 // of its bytes. Its source maps go up with each deploy96 // (`upload_source_maps` in wrangler.jsonc), so a stack trace in the97 // Worker's logs still names the source.98 environments: { ssr: { build: { minify: true, sourcemap: true } } },Merge chore/web-dev-host into mainoscabrielbefore adoption4a9b05a
line 99why, one step back99 };Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
line 100why, one step back100});