Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guide/app-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
14 changes: 13 additions & 1 deletion packages/void/src/cli/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
}
Expand Down Expand Up @@ -379,6 +379,18 @@ function hasViteLike(pkg: Record<string, unknown>): 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, unknown>): string {
return hasPackageDependency(pkg, 'void') ? 'dist/client' : 'dist';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Distinguish CLI installation from use of the Vite plugin

For a plain Vite SPA that installs void to use its deployment CLI but does not enable voidPlugin(), this changes the upload directory to dist/client even though the build still produces dist/index.html. Both deploy-managed-static.ts and deploy-cloudflare-static.ts reject the nonexistent output directory after a successful build, so previously working static deployments now fail. A void dependency does not establish that its Vite plugin runs; determine whether the split build layout is actually used before selecting dist/client, while retaining dist for CLI-only installations.

Useful? React with 👍 / 👎.

}

function detectViteBinary(root: string): 'vite' | 'vp' {
const pkg = readPackageJson(root);
if (pkg && hasPackageDependency(pkg, 'vite-plus')) {
Expand Down
25 changes: 25 additions & 0 deletions packages/void/test/unit/preset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': '<html></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': '<html></html>' },
Expand Down
Loading