Skip to content

Commit

Permalink
feat(preview): improve error when build output missing
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Feb 17, 2023
1 parent 6eee75c commit 6e13272
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/vite/src/node/preview.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6e13272

Please sign in to comment.