Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "restart" on save in Visual Studio Code?

I've setup the Debugging with Chrome and it works reasonably well. However, every time I make a change & save the .htm file, I have to click the Restart icon in the toolbar for the changes to propagate to the instance of Chrome.

Is there a way for VS Code to "restart" when I save the file?

P.S. I am editing a local file (no web servers involved).

like image 959
AngryHacker Avatar asked Nov 30 '17 01:11

AngryHacker


People also ask

How do I revert saved changes in VS code?

Click the (...) button and then select Undo Last Commit to undo the previous commit. The changes are added to the Staged Changes section.

How do I start autoSave in Vscode?

The easiest way to turn on Auto Save is with the File > Auto Save toggle that turns on and off save after a delay. For more control over Auto Save , open User or Workspace settings and find the associated settings: files.autoSave : Can have the values: off - to disable auto save.


1 Answers

I wanted to do exactly the same thing and accomplished it by installing an extension that allows me to execute a VS Code extension command when a file is saved.

The extension is Save and Run Ext and is a fork off of another extension but allows you to execute VS Code extension commands.

I added the following configuration to my settings.json file:

{
  "saveAndRunExt": {
    "commands": [
      {
        "match": "\\.(css$|js$|html$)",
        "isShellCommand": false,
        "cmd": "workbench.action.debug.restart"
      }
    ]
  }
}

What this does is whenever a .css, .js, or .html file is saved, it will restart the debugger. You could of course configure it to do whatever you want.

An alternative (one step) solution is instead of saving the file, just restart the debugger, and it automatically saves all files and changes are propagated to Chrome.

like image 129
Don Nguyen Avatar answered Oct 01 '22 02:10

Don Nguyen