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: check whether to build before preview #11570

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
10 changes: 9 additions & 1 deletion packages/vite/src/node/preview.ts
@@ -1,4 +1,5 @@
import path from 'node:path'
import fs from 'node:fs'
import type * as http from 'node:http'
import sirv from 'sirv'
import connect from 'connect'
Expand Down Expand Up @@ -83,6 +84,14 @@ export async function preview(
'production',
)

const distDir = path.resolve(config.root, config.build.outDir)
const isAlreadyBuild = fs.existsSync(distDir)
if (!isAlreadyBuild) {
throw Error(
'The outputDir cannot be found, please try again after building',
)
}

const app = connect() as Connect.Server
const httpServer = await resolveHttpServer(
config.preview,
Expand Down Expand Up @@ -115,7 +124,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