Skip to content

Commit 7fd7c6c

Browse files
authored
feat(server): allow disabling built-in shortcuts (#15218)
1 parent 73e971f commit 7fd7c6c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: packages/vite/src/node/shortcuts.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ export type BindCLIShortcutsOptions<Server = ViteDevServer | PreviewServer> = {
1414
/**
1515
* Custom shortcuts to run when a key is pressed. These shortcuts take priority
1616
* over the default shortcuts if they have the same keys (except the `h` key).
17+
* To disable a default shortcut, define the same key but with `action: undefined`.
1718
*/
1819
customShortcuts?: CLIShortcut<Server>[]
1920
}
2021

2122
export type CLIShortcut<Server = ViteDevServer | PreviewServer> = {
2223
key: string
2324
description: string
24-
action(server: Server): void | Promise<void>
25+
action?(server: Server): void | Promise<void>
2526
}
2627

2728
export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
@@ -66,6 +67,8 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
6667
if (loggedKeys.has(shortcut.key)) continue
6768
loggedKeys.add(shortcut.key)
6869

70+
if (shortcut.action == null) continue
71+
6972
server.config.logger.info(
7073
colors.dim(' press ') +
7174
colors.bold(`${shortcut.key} + enter`) +
@@ -77,7 +80,7 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
7780
}
7881

7982
const shortcut = shortcuts.find((shortcut) => shortcut.key === input)
80-
if (!shortcut) return
83+
if (!shortcut || shortcut.action == null) return
8184

8285
actionRunning = true
8386
await shortcut.action(server)

0 commit comments

Comments
 (0)