如何使用新的Microsoft Visual Studio code在浏览器中查看我的HTML代码?
使用notepad++,您可以选择在浏览器中运行。我如何用Visual Studio Code做同样的事情?
如何使用新的Microsoft Visual Studio code在浏览器中查看我的HTML代码?
使用notepad++,您可以选择在浏览器中运行。我如何用Visual Studio Code做同样的事情?
当前回答
Windows -打开默认浏览器-在VS Code v 1.1.0上测试
回答既打开一个特定的文件(名称是硬编码)或打开任何其他文件。
步骤:
Use ctrl + shift + p (or F1) to open the Command Palette. Type in Tasks: Configure Task or on older versions Configure Task Runner. Selecting it will open the tasks.json file. Delete the script displayed and replace it by the following: { "version": "0.1.0", "command": "explorer", "windows": { "command": "explorer.exe" }, "args": ["test.html"] } Remember to change the "args" section of the tasks.json file to the name of your file. This will always open that specific file when you hit F5. You may also set the this to open whichever file you have open at the time by using ["${file}"] as the value for "args". Note that the $ goes outside the {...}, so ["{$file}"] is incorrect. Save the file. Switch back to your html file (in this example it's "text.html"), and press ctrl + shift + b to view your page in your Web Browser.
其他回答
我的运行脚本看起来像这样:
{
"version": "0.1.0",
"command": "explorer",
"windows": {
"command": "explorer.exe"
},
"args": ["{$file}"]
}
当我在index。html文件中按ctrl shift b,它就会打开我的资源管理器
Windows -打开默认浏览器-在VS Code v 1.1.0上测试
回答既打开一个特定的文件(名称是硬编码)或打开任何其他文件。
步骤:
Use ctrl + shift + p (or F1) to open the Command Palette. Type in Tasks: Configure Task or on older versions Configure Task Runner. Selecting it will open the tasks.json file. Delete the script displayed and replace it by the following: { "version": "0.1.0", "command": "explorer", "windows": { "command": "explorer.exe" }, "args": ["test.html"] } Remember to change the "args" section of the tasks.json file to the name of your file. This will always open that specific file when you hit F5. You may also set the this to open whichever file you have open at the time by using ["${file}"] as the value for "args". Note that the $ goes outside the {...}, so ["{$file}"] is incorrect. Save the file. Switch back to your html file (in this example it's "text.html"), and press ctrl + shift + b to view your page in your Web Browser.
我只是重新发布我从msdn博客使用的步骤。这可能对社区有所帮助。
这将帮助你 使用VS Code设置一个本地web服务器,称为lite-server,并指导你在localhost中托管静态html文件和调试Javascript代码。
1. 安装node . js
如果还没有安装,请从这里获取
它带有npm(用于获取和管理开发库的包管理器)
2. 为项目创建一个新文件夹
在你的驱动器的某个地方,为你的web应用程序创建一个新文件夹。
3.添加包。Json文件到项目文件夹
然后复制/粘贴以下文本:
{
"name": "Demo",
"version": "1.0.0",
"description": "demo project.",
"scripts": {
"lite": "lite-server --port 10001",
"start": "npm run lite"
},
"author": "",
"license": "ISC",
"devDependencies": {
"lite-server": "^2.5.4"
}
}
4. 安装web服务器
在项目文件夹上打开的终端窗口(Windows中的命令提示符)中,运行以下命令:
npm install
这将安装lite-server(在package.json中定义),这是一个静态服务器,它在默认浏览器中加载index.html,并在应用程序文件更改时自动刷新它。
5. 启动本地web服务器!
(假设在项目文件夹中有index.html文件)。
在同一终端窗口(Windows中的命令提示符)运行以下命令:
npm start
等待一秒钟,index.html被加载并显示在您本地web服务器提供的默认浏览器中!
Lite-server正在监视您的文件,并在您对任何html, js或CSS文件进行更改时刷新页面。
如果你将VS Code配置为自动保存(菜单文件/自动保存),你会在浏览器中看到你输入的变化!
注:
不要关闭命令行提示符,直到您在 每日应用 它在http://localhost:10001上打开,但是您可以通过更改端口 编辑包。json文件。
就是这样。现在,在任何编码会话之前,只需输入npm start,你就可以开始了!
最初发表于msdn博客。 致谢作者:@Laurent Duveau
下面是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}"
]
}
]
}
打开自定义Chrome浏览器与URL从提示
{
"version": "2.0.0",
"tasks": [
{
"label": "Open Chrome",
"type": "process",
"windows": {
"command": "${config:chrome.executable}"
},
"args": ["--user-data-dir=${config:chrome.profileDir}", "${input:url}"],
"problemMatcher": []
}
],
"inputs": [
{
"id": "url",
"description": "Which URL?",
"default": "http://localhost:8080",
"type": "promptString"
}
]
}
打开自定义Chrome与活动文件
{
"label": "Open active file in Chrome",
"type": "process",
"command": "chrome.exe",
"windows": {
"command": "${config:chrome.executable}"
},
"args": ["--user-data-dir=${config:chrome.profileDir}", "${file}"],
"problemMatcher": []
},
笔记
如有必要,可将windows属性替换为其他操作系统 替换${配置:chrome。可执行}与您的自定义chrome位置,例如。"C:/Program Files (x86)/谷歌/Chrome/Application/ Chrome .exe" 替换${配置:chrome。profileDir}与您的自定义chrome配置文件目录,例如。 “C:/My/Data/chrome/profile”或省略 如果你愿意,你可以像上面那样保留变量。为此,在设置中添加以下条目。Json -用户或工作区-,根据需要调整路径:
"chrome.executable": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
"chrome.profileDir": "C:/My/Data/chrome/profile"
你可以重复使用这些变量,例如在启动。"runtimeExecutable": "${config:chrome.executable}"