Files
vercel__workflow/packages/web/react-router.config.ts
Nathan Rajlich 45d1eb2340 web: configure vercelPreset() for Vercel deployments (#1815)
* web: configure vercelPreset() for Vercel deployments

Enables per-route bundle splitting, function-level configuration, and an
accurate Deployment Summary for the packages/web Vercel deployment.

Gated on WORKFLOW_WEB_VERCEL_BUILD (rather than the ambient VERCEL var)
so that the standard build layout consumed by server.js (self-hosted
deployments and the CLI's in-process server via @workflow/web/server) is
still produced when the package is packed as a tarball by the docs
Vercel deployment. Existing VERCEL-based checks in vite.config.ts have
been migrated to this same variable for consistency.

* web: allow WORKFLOW_WEB_VERCEL_BUILD through Turborepo

Turborepo strips environment variables not declared in turbo.json, which
prevented WORKFLOW_WEB_VERCEL_BUILD (set on the Vercel project) from
reaching the build. Declare it in the env list and also include the
.vercel/ directory (where the preset writes react-router-build-result.json)
in the build outputs.

* web: narrow Turbo output to react-router-build-result.json

* web: address PR review feedback

- Check WORKFLOW_WEB_VERCEL_BUILD === '1' explicitly (rejects '0', 'false',
  etc.) in both react-router.config.ts and vite.config.ts
- Use double-quoted package name in changeset frontmatter to match the
  repo's dominant convention
2026-05-04 10:04:21 +00:00

23 lines
977 B
TypeScript

import type { Config } from '@react-router/dev/config';
import { vercelPreset } from '@vercel/react-router/vite';
// Enable the Vercel preset only when building the `packages/web` Vercel
// deployment itself. The preset changes the server build layout (per-route
// bundles under `build/server/<runtime>_<hash>/`), which breaks `server.js`
// (used for self-hosting and by the CLI via `@workflow/web/server`) since it
// imports `build/server/index.js`.
//
// We cannot gate this on `process.env.VERCEL` alone because the `docs`
// deployment also runs `pnpm pack` on this package with `VERCEL=1` set, and
// in that case we need the standard layout so the published tarball works.
// Set `WORKFLOW_WEB_VERCEL_BUILD=1` in the web Vercel project's environment
// variables to opt in.
const presets: Config['presets'] =
process.env.WORKFLOW_WEB_VERCEL_BUILD === '1' ? [vercelPreset()] : [];
export default {
appDirectory: 'app',
ssr: true,
presets,
} satisfies Config;