From 154d3ca016619d722d7482b50c91027e9cc4513e Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 24 Nov 2026 06:12:43 +0800 Subject: [PATCH] fix(deploy): upload dist/client for a Vite app built with void A Vite app that depends on `void` builds with voidPlugin(), which writes browser files to dist/client and the server bundle, its source map and wrangler.json to dist/ssr. With no backend files, detectPreset step 4 picked `dist` as the static output, so `void deploy` published the server files and `/` returned 404 (index.html sat at /client/index.html). Pick dist/client in that case. A plain Vite app keeps `dist`. Co-Authored-By: Claude Opus 5.5 --- docs/guide/app-types.md | 2 +- docs/reference/config.md | 2 +- packages/void/src/cli/preset.ts | 14 +++++++++++++- packages/void/test/unit/preset.test.ts | 25 +++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/docs/guide/app-types.md b/docs/guide/app-types.md index 5dfa403e6..60269c39e 100644 --- a/docs/guide/app-types.md +++ b/docs/guide/app-types.md @@ -116,4 +116,4 @@ To lock the app type and skip auto-detection, set `inference.appType` in [`void. ``` - `inference.appType`: `"void"`, `"framework"`, `"spa"`, or `"static"` -- `inference.outputDir`: output directory for static app types (relative to project root, defaults to `"dist"`) +- `inference.outputDir`: output directory for static app types (relative to project root). Defaults to `"dist"`, or `"dist/client"` when the project depends on `void`, because `voidPlugin()` writes browser files there diff --git a/docs/reference/config.md b/docs/reference/config.md index 2b3c012ce..4786a50bb 100644 --- a/docs/reference/config.md +++ b/docs/reference/config.md @@ -622,4 +622,4 @@ App type. If omitted, auto-detected on first deploy. See [Supported App Types](. #### `inference.outputDir` -Output directory for static deploys, relative to the project root. Only relevant when `inference.appType` is `"spa"` or `"static"`. Defaults to `"dist"`. +Output directory for static deploys, relative to the project root. Only relevant when `inference.appType` is `"spa"` or `"static"`. Defaults to `"dist"`, or `"dist/client"` when the project depends on `void`, because `voidPlugin()` writes browser files there and server files to `dist/ssr`. diff --git a/packages/void/src/cli/preset.ts b/packages/void/src/cli/preset.ts index 6b6b4a471..29c692a9e 100644 --- a/packages/void/src/cli/preset.ts +++ b/packages/void/src/cli/preset.ts @@ -279,7 +279,7 @@ export function detectPreset( const buildCommand = resolveProjectScriptCommand(root, 'build'); return { buildCommand: buildCommand ?? resolveProjectCommand(root, 'vite build'), - outputDir: resolve(root, 'dist'), + outputDir: resolve(root, viteSpaOutputDir(pkg)), appType: 'spa', }; } @@ -379,6 +379,18 @@ function hasViteLike(pkg: Record): boolean { return hasPackageDependency(pkg, 'vite') || hasPackageDependency(pkg, 'vite-plus'); } +/** + * Where a Vite SPA build puts its browser files. A project that depends on + * `void` builds with `voidPlugin()` (`void init` adds it), which splits the + * output into `dist/client` (browser files) and `dist/ssr` (the server + * bundle, its source map and `wrangler.json`). Only `dist/client` may be + * uploaded: uploading `dist` publishes the server files and leaves `/` + * without an `index.html`. + */ +function viteSpaOutputDir(pkg: Record): string { + return hasPackageDependency(pkg, 'void') ? 'dist/client' : 'dist'; +} + function detectViteBinary(root: string): 'vite' | 'vp' { const pkg = readPackageJson(root); if (pkg && hasPackageDependency(pkg, 'vite-plus')) { diff --git a/packages/void/test/unit/preset.test.ts b/packages/void/test/unit/preset.test.ts index 588ceffc7..76705dd47 100644 --- a/packages/void/test/unit/preset.test.ts +++ b/packages/void/test/unit/preset.test.ts @@ -153,6 +153,31 @@ describe('detectPreset', () => { }); }); + // voidPlugin() splits the build into dist/client and dist/ssr. Uploading dist + // published the server bundle, its source map and wrangler.json, and left / + // without an index.html. + it('uploads only dist/client for a Vite app built with void and no backend', () => { + const root = setupProject({ + pkg: { devDependencies: { 'vite-plus': '^1.0.0', void: '^0.5.0' } }, + files: { 'index.html': '', 'main.js': '' }, + }); + expect(detectPreset(root)).toEqual({ + buildCommand: 'vp build', + outputDir: toSlash(resolve(root, 'dist/client')), + appType: 'spa', + }); + }); + + it('uses dist/client for a configured static app built with void', () => { + const root = setupProject({ + pkg: { dependencies: { vite: '^6.0.0', void: '^0.5.0' } }, + }); + const config = { inference: { appType: 'spa' } } as VoidConfig; + expect(resolveCloudflareStaticPreset(root, config, {})?.outputDir).toBe( + toSlash(resolve(root, 'dist/client')), + ); + }); + it('detects pre-built dist/index.html as static', () => { const root = setupProject({ files: { 'dist/index.html': '' },