How to view my HTML code in a browser with the new Microsoft Visual Studio Code?
With Notepad++ you have the option to Run in a browser. How can I do the same thing with Visual Studio Code?
How to view my HTML code in a browser with the new Microsoft Visual Studio Code?
With Notepad++ you have the option to Run in a browser. How can I do the same thing with Visual Studio Code?
In linux, you can use the
xdg-open
command to open the file with the default browser:If you would like to have live reload you can use gulp-webserver, which will watch for your file changes and reload page, this way you don't have to press F5 every time on your page:
Here is how to do it:
Open command prompt (cmd) and type
npm install --save-dev gulp-webserver
Enter Ctrl+Shift+P in VS Code and type Configure Task Runner. Select it and press enter. It will open tasks.json file for you. Remove everything from it end enter just following code
tasks.json
gulpfile.js
Your webserver now will open your page in your default browser. Now any changes that you will do to your HTML or CSS pages will be automatically reloaded.
Here is an information on how to configure 'gulp-webserver' for instance port, and what page to load, ...
You can also run your task just by entering Ctrl+P and type task webserver
@InvisibleDev - to get this working on a mac trying using this:
If you have chrome already open, it will launch your html file in a new tab.
Here is a 2.0.0 version for the current document in Chrome w/ keyboard shortcut:
tasks.json
keybindings.json
:For running on a webserver:
https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer
For Windows - Open your Default Browser - Tested on VS Code v 1.1.0
Answer to both opening a specific file (name is hard-coded) OR opening ANY other file.
Steps:
Use ctrl + shift + p (or F1) to open the Command Palette.
Type in
Tasks: Configure Task
or on older versionsConfigure Task Runner
. Selecting it will open the tasks.json file. Delete the script displayed and replace it by the following: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.
Openning files in Opera browser (on Windows 64 bits). Just add this lines:
Pay attention to the path format on "command": line. Don't use the "C:\path_to_exe\runme.exe" format.
To run this task, open the html file you want to view, press F1, type task opera and press enter