Is there a way to see a preview of the webpage?

I was wondering if there is a way to see a preview of the page of the webpage we are working on in a web browser directly from the Visual Studio Code Editor, instead of clicking on the file to open it by the default web browser.

+3


source to share


2 answers


You can open your Visual Studio Code project in a browser window by setting up a gulp task using the node gulp-open module. Then you can run the gulp task from Visual Studio Code.

You can set up a gulp task here:

var open = require('gulp-open');
gulp.task('browser', function(){
  // Define the source to match the file you wish to open:
  gulp.src('./www/index.html')
    // Designate the browser you wish the file opened in:
    .pipe(open('<%file.path%>', {app: 'google-chrome'}));
  });
});

      



Since we named our task "browser", from within Visual Studio Code we can press command / control P to invoke the command bar task and type. Then start typing browser. You should see the complete code for the complete task as you type. Press Return and it will open your file in the browser you specified. When the browser is open, you can resize it and Visual Studio Code so that they are side by side. Then, when you're working, you can refresh your browser to see your changes.

You can refer to the docs for gulp-open in NPM .

+2


source


Directly from the editor there are WYSIWYG editors such as Adobe Dreamweaver, Kompozer, etc. Though they often offer poor previews for anything other than plain HTML and CSS (i.e. no JS, no animations, and possibly other CSS support).

Using a text editor like Visual Studio Code Editor, Sublime Text or vim, there is no such preview feature.



Ideally, you want to test in the browser (the browsers that you expect to target your target audience) to make sure you have an idea of ​​what your visitors will see.

To save time between coding and preview, you can simply open a window / tab in Chrome / Firefox / Edge and refresh after you save the file in the editor.

+1


source







All Articles