You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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, press Ctrl+C (Windows/Linux) or Cmd+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:

    1. Open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P), type "Tasks: Open Workspace Tasks" (recommended for project-specific settings) and select it.
    2. Choose "Create tasks.json file from template" > "Others".
    3. Replace the default content with this configuration (swap npm run dev for 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"
            }
          }
        ]
      }
      
    4. 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.

  • Extension-powered button workflow
    If you’re set on a button-based experience like IntelliJ’s, try these third-party extensions:

    • The npm Scripts extension 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 Restart lets 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).

内容的提问来源于stack exchange,提问作者Jöcker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 07:52:34