如何“重启"保存在 Visual Studio Code 中? [英] How to "restart" on save in Visual Studio Code?

查看:26
本文介绍了如何“重启"保存在 Visual Studio Code 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用 Chrome 设置了调试,它运行得相当好.然而,每次我做出改变&保存 .htm 文件,我必须单击工具栏中的重新启动图标才能将更改传播到 Chrome 实例.

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.

当我保存文件时,VS Code 有没有办法重新启动"?

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).

推荐答案

我想做完全相同的事情并通过安装一个扩展来实现它,该扩展允许我在保存文件时执行 VS Code 扩展命令.

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.

扩展名是保存并运行Ext 是另一个扩展的分支,但允许您执行 VS Code 扩展命令.

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

我在我的 settings.json 文件中添加了以下配置:

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

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

它的作用是每当保存 .css、.js 或 .html 文件时,它将重新启动调试器.您当然可以将其配置为做任何您想做的事情.

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.

另一种(一步)解决方案是不保存文件,只需重新启动调试器,它就会自动保存所有文件并将更改传播到 Chrome.

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.

这篇关于如何“重启"保存在 Visual Studio Code 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆