0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-04-07 23:41:43 -05:00

Error on preview if outDir missing (#9544)

* Error on preview if outDir missing

* Update .changeset/four-moles-burn.md

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

---------

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
This commit is contained in:
Bjorn Lu 2024-01-03 21:05:51 +08:00 committed by GitHub
parent ab6049bd58
commit b8a6fa8917
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'astro': minor
---
Adds a helpful error for static sites when you use the `astro preview` command if you have not previously run `astro build`.

View file

@ -1,3 +1,4 @@
import fs from 'node:fs';
import { createRequire } from 'node:module';
import { fileURLToPath, pathToFileURL } from 'node:url';
import type { AstroInlineConfig, PreviewModule, PreviewServer } from '../../@types/astro.js';
@ -34,6 +35,12 @@ export default async function preview(inlineConfig: AstroInlineConfig): Promise<
await runHookConfigDone({ settings: settings, logger: logger });
if (settings.config.output === 'static') {
if (!fs.existsSync(settings.config.outDir)) {
const outDirPath = fileURLToPath(settings.config.outDir);
throw new Error(
`[preview] The output directory ${outDirPath} does not exist. Did you run \`astro build\`?`
);
}
const server = await createStaticPreviewServer(settings, logger);
return server;
}