Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(preview): improve error when build output missing #12096

Merged
merged 2 commits into from Feb 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/vite/src/node/preview.ts
@@ -1,3 +1,4 @@
import fs from 'node:fs'
import path from 'node:path'
import type * as http from 'node:http'
import sirv from 'sirv'
Expand Down Expand Up @@ -84,6 +85,16 @@ export async function preview(
'production',
)

const distDir = path.resolve(config.root, config.build.outDir)
if (
!fs.existsSync(distDir) &&
config.plugins.every((plugin) => !plugin.configurePreviewServer)
) {
throw new Error(
`The directory "${config.build.outDir}" does not exist. Did you build your project?`,
)
}

const app = connect() as Connect.Server
const httpServer = await resolveHttpServer(
config.preview,
Expand Down Expand Up @@ -116,7 +127,6 @@ export async function preview(
config.base === './' || config.base === '' ? '/' : config.base

// static assets
const distDir = path.resolve(config.root, config.build.outDir)
const headers = config.preview.headers
const assetServer = sirv(distDir, {
etag: true,
Expand Down