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?
Step 1:
Search for "open in browser".
3.Install it.
4.Right click on your html file,you will find the option "Open in Browser".
That's All......................................................
If you're just on Mac this
tasks.json
file:...is all you need to open the current file in Safari, assuming its extension is ".html".
Create
tasks.json
as described above and invoke it with ⌘+shift+b.If you want it to open in Chrome then:
This will do what you want, as in opening in a new tab if the app is already open.
One click solution simply install open-in-browser Extensions from the Visual Studio marketplace.
I am just re-posting the steps I used from
msdn
blog. It may help the community.This will help you to setup a local web server known as lite-server with
VS Code
, and also guides you to host your statichtml
files inlocalhost
anddebug
yourJavascript
code.1. Install Node.js
If not already installed, get it here
It comes with npm (the package manager for acquiring and managing your development libraries)
2. Create a new folder for your project
Somewhere in your drive, create a new folder for your web app.
3. Add a package.json file to the project folder
Then copy/paste the following text:
4. Install the web server
In a terminal window (command prompt in Windows) opened on your project folder, run this command:
This will install lite-server (defined in package.json), a static server that loads index.html in your default browser and auto refreshes it when application files change.
5. Start the local web server!
(Assuming you have an index.html file in your project folder).
In the same terminal window (command prompt in Windows) run this command:
Wait a second and index.html is loaded and displayed in your default browser served by your local web server!
lite-server is watching your files and refreshes the page as soon as you make changes to any html, js or css files.
And if you have VS Code configured to auto save (menu File / Auto Save), you see changes in the browser as you type!
Notes:
That’s it. Now before any coding session just type npm start and you are good to go!
Originally posted here in
msdn
blog. Credits goes to Author :@Laurent Duveau
probably most will be able to find a solution from the above answers but seeing as how none worked for me (
vscode v1.34
) i thought i'd share my experience. if at least one person finds it helpful then, cool not a wasted post, amiirte?anyway, my solution (
windows
) is built a-top of @noontz's. his configuration may have been sufficient for older versions ofvscode
but not with1.34
(at least, i couldn't get it working ..).our configs are nearly identical save a single property -- that property being, the
group
property. i'm not sure why but without this, my task would not even appear in the command palette.so. a working
tasks.json
forwindows
users runningvscode 1.34
:note that the
problemMatcher
property is not required for this to work but without it an extra manual step is imposed on you. tried to read the docs on this property but i'm too thick to understand. hopefully someone will come about and school me but yeah, thanks in advance for that. all i know is -- include this property andctrl+shift+b
opens the currenthtml
file in a newchrome
tab, hassle free.easy.
CTRL+SHIFT+P
will bring up the command palette.Depending on what you're running of course. Example in an ASP.net app you can type in:
>kestrel
and then open up your web browser and type inlocalhost:(your port here)
.If you type in
>
it will show you the show and run commandsOr in your case with HTML, I think
F5
after opening the command palette should open the debugger.Source: link