diff --git a/packages/vite/src/node/shortcuts.ts b/packages/vite/src/node/shortcuts.ts index 9a8dac1c457983..51584c66d48021 100644 --- a/packages/vite/src/node/shortcuts.ts +++ b/packages/vite/src/node/shortcuts.ts @@ -14,6 +14,7 @@ export type BindCLIShortcutsOptions = { /** * Custom shortcuts to run when a key is pressed. These shortcuts take priority * over the default shortcuts if they have the same keys (except the `h` key). + * To disable a default shortcut, define the same key but with `action: undefined`. */ customShortcuts?: CLIShortcut[] } @@ -21,7 +22,7 @@ export type BindCLIShortcutsOptions = { export type CLIShortcut = { key: string description: string - action(server: Server): void | Promise + action?(server: Server): void | Promise } export function bindCLIShortcuts( @@ -66,6 +67,8 @@ export function bindCLIShortcuts( if (loggedKeys.has(shortcut.key)) continue loggedKeys.add(shortcut.key) + if (shortcut.action == null) continue + server.config.logger.info( colors.dim(' press ') + colors.bold(`${shortcut.key} + enter`) + @@ -77,7 +80,7 @@ export function bindCLIShortcuts( } const shortcut = shortcuts.find((shortcut) => shortcut.key === input) - if (!shortcut) return + if (!shortcut || shortcut.action == null) return actionRunning = true await shortcut.action(server)