Visual Studio Code中是否有类似IntelliJ的npm脚本重启按钮?
Great question! VS Code doesn’t have a built-in one-click restart button for npm scripts like IntelliJ does out of the box, but there are several workarounds that can make this process just as smooth:
Quick terminal-based restart
This is the simplest default method. In the terminal window running your npm script, pressCtrl+C(Windows/Linux) orCmd+C(Mac) to kill the active process. Then hit the up arrow key (↑) to quickly recall your npm command (e.g.,npm run dev) and press Enter to restart—no need to close the entire terminal, which saves you a step compared to your current workflow.Custom task with keyboard shortcut
You can package the "kill old process + start new script" action into a custom task, then bind it to a keyboard shortcut for one-touch restarts:- Open the Command Palette (
Ctrl+Shift+P/Cmd+Shift+P), type "Tasks: Open Workspace Tasks" (recommended for project-specific settings) and select it. - Choose "Create tasks.json file from template" > "Others".
- Replace the default content with this configuration (swap
npm run devfor your actual script command):{ "version": "2.0.0", "tasks": [ { "label": "Restart npm Script", "type": "shell", "command": "pkill -f 'npm run dev' || true && npm run dev", "problemMatcher": [], "presentation": { "reveal": "always", "panel": "new" } } ] } - Bind a shortcut: Open the Command Palette again, type "Preferences: Open Keyboard Shortcuts (JSON)", and add this entry (adjust the key combo to your preference):
{ "key": "ctrl+shift+r", "command": "workbench.action.tasks.runTask", "args": "Restart npm Script" }
Now you can restart your script with just a quick key press.
- Open the Command Palette (
Extension-powered button workflow
If you’re set on a button-based experience like IntelliJ’s, try these third-party extensions:- The
npm Scriptsextension displays all your project’s npm scripts in the sidebar, with some versions offering a "Restart" option in the right-click menu for running scripts. Terminal Restartlets you restart the active terminal with a single button click—just launch your npm script first, then hit the extension’s button to reboot the terminal (and your script along with it).
- The
内容的提问来源于stack exchange,提问作者Jöcker

