Skip to content

Commit 4356485

Browse files
Jacob Lambematipicosarah11918florian-lefebvre
authored
feat(cli): Add preview shortcuts (#14574)
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
1 parent 0419985 commit 4356485

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

.changeset/real-ends-switch.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'astro': minor
3+
---
4+
5+
Adds new CLI shortcuts available when running `astro preview`:
6+
7+
- `o` + `enter`: open the site in your browser
8+
- `q` + `enter`: quit the preview
9+
- `h` + `enter`: print all available shortcuts

packages/astro/src/core/preview/static-preview-server.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type http from 'node:http';
22
import { performance } from 'node:perf_hooks';
33
import { fileURLToPath } from 'node:url';
4+
import type * as vite from 'vite';
45
import { preview, type PreviewServer as VitePreviewServer } from 'vite';
56
import type { AstroSettings } from '../../types/astro.js';
67
import type { Logger } from '../logger/core.js';
@@ -47,6 +48,20 @@ export default async function createStaticPreviewServer(
4748
throw err;
4849
}
4950

51+
// Set up shortcuts
52+
53+
const customShortcuts: Array<vite.CLIShortcut> = [
54+
// Disable default Vite shortcuts that don't work well with Astro
55+
{ key: 'r', description: '' },
56+
{ key: 'u', description: '' },
57+
{ key: 'c', description: '' },
58+
{ key: 's', description: '' },
59+
];
60+
61+
previewServer.bindCLIShortcuts({
62+
customShortcuts,
63+
});
64+
5065
// Log server start URLs
5166
logger.info(
5267
'SKIP_FORMAT',

0 commit comments

Comments
 (0)