如何使用新的Microsoft Visual Studio code在浏览器中查看我的HTML代码?
使用notepad++,您可以选择在浏览器中运行。我如何用Visual Studio Code做同样的事情?
如何使用新的Microsoft Visual Studio code在浏览器中查看我的HTML代码?
使用notepad++,您可以选择在浏览器中运行。我如何用Visual Studio Code做同样的事情?
当前回答
在linux下,可以使用xdg-open命令在默认浏览器下打开文件:
{
"version": "0.1.0",
"linux": {
"command": "xdg-open"
},
"isShellCommand": true,
"showOutput": "never",
"args": ["${file}"]
}
其他回答
我的运行脚本看起来像这样:
{
"version": "0.1.0",
"command": "explorer",
"windows": {
"command": "explorer.exe"
},
"args": ["{$file}"]
}
当我在index。html文件中按ctrl shift b,它就会打开我的资源管理器
下面是Mac OSx的2.0.0版本:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello"
},
{
"label":"chrome",
"type":"process",
"command":"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"args": [
"${file}"
]
}
]
}
下面是如何在Windows的多个浏览器中运行它
{
"version": "0.1.0",
"command": "cmd",
"args": ["/C"],
"isShellCommand": true,
"showOutput": "always",
"suppressTaskName": true,
"tasks": [
{
"taskName": "Chrome",
"args": ["start chrome -incognito \"${file}\""]
},
{
"taskName": "Firefox",
"args": ["start firefox -private-window \"${file}\""]
},
{
"taskName": "Edge",
"args": ["${file}"]
}
]
}
注意,我没有为edge在args中输入任何东西,因为edge是我的默认浏览器,只是给了它文件名。
编辑:你也不需要-incognito或-private-window…只有我,我喜欢在私人窗口看
可能大多数人都能从上面的答案中找到一个解决方案,但看到没有一个对我有效(vscode v1.34),我想我将分享我的经验。如果至少有一个人觉得它有帮助,那么很酷,不是一个浪费的帖子,amiirte?
无论如何,我的解决方案(窗口)是建立在@noontz的顶部。他的配置可能已经足够旧版本的vscode,但不是1.34(至少,我不能让它工作..)。
我们的配置几乎是相同的,除了一个属性,即group属性。我不知道为什么,但是如果没有这个,我的任务甚至不会出现在命令面板中。
所以。一个工作任务。Json,用于运行vscode 1.34的Windows用户:
{
"version": "2.0.0",
"tasks": [
{
"label": "Chrome",
"type": "process",
"command": "chrome.exe",
"windows": {
"command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
},
"args": [
"${file}"
],
"group": "build",
"problemMatcher": []
}
]
}
请注意,这个工作并不需要problemMatcher属性,但是如果没有它,就需要额外的手动步骤。我试过看这房子的文件,但我太笨了,看不懂。希望有人能过来教我,不过先谢谢你了。我所知道的是——包括这个属性和ctrl+shift+b打开当前的HTML文件在一个新的chrome选项卡,麻烦的自由。
一件容易的事。
Live Preview扩展刚刚添加了(在Insiders Build now和稳定2023年2月初)改变打开默认浏览器的能力(当你选择在外部浏览器中打开它,而不是在vscode中的另一个选项卡中打开它)。参见添加选项以选择默认外部浏览器。
背景是
Live Preview: Custom External Browser
livePreview.customExternalBrowser
选项:Edge、Chrome、Firefox、无
没有一个浏览器会使用您在操作系统中设置的默认浏览器。新的设置允许您覆盖默认设置与另一个浏览器的目的Live预览扩展打开外部浏览器,通过命令:
Live Preview: Show Preview (External Browser)