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:
parent
ab6049bd58
commit
b8a6fa8917
2 changed files with 12 additions and 0 deletions
5
.changeset/four-moles-burn.md
Normal file
5
.changeset/four-moles-burn.md
Normal 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`.
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue