Skip to content

Commit

Permalink
fix: error on cli only
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Feb 17, 2023
1 parent 6e13272 commit a71c305
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/vite/src/node/preview.ts
Expand Up @@ -88,7 +88,12 @@ export async function preview(
const distDir = path.resolve(config.root, config.build.outDir)
if (
!fs.existsSync(distDir) &&
config.plugins.every((plugin) => !plugin.configurePreviewServer)
// error if no plugins implement `configurePreviewServer`
config.plugins.every((plugin) => !plugin.configurePreviewServer) &&
// error if called in CLI only. programmatic usage could access `httpServer`
// and affect file serving
process.argv[1]?.endsWith(path.normalize('bin/vite.js')) &&
process.argv[2] === 'preview'
) {
throw new Error(
`The directory "${config.build.outDir}" does not exist. Did you build your project?`,
Expand Down

0 comments on commit a71c305

Please sign in to comment.