Launching your first webapp in Visual Studio Code through Gulp


I figured it’s about time I get a little more experienced with AngularJS. I want to create a website for my project VSDiagnostics and I plan on working with this technology at my internship, so it’s time to jump on the hype train.

What you’ll read here is just a quick overview of setting up gulp and Visual Studio Code to get your first AngularJS app working.

Download Visual Studio Code

This is our editor of choice. If you prefer to use something else then that’s fine — anything that can write plain text files is fine, really. I would suggest Notepad++ or Sublime Text as an alternative.

Visual Studio Code

Install NodeJS

The Node Package Manager (npm) will help us retrieve all the dependencies we’re interested in. Likewise, if you ever want to add a NodeJS backend — this will be needed.

Create a directory structure

I created my folder structure like this:

Write code

I’m working through a book on AngularJS myself so the little bit of AngularJS code here is just the first two examples shown in that book. It’s a simple demonstration of model-binding — a powerful feature of the AngularJS framework.

Once all this is done, I bet you’re interested to see what we just created. However if you’ll look around in the Visual Studio Code IDE, you’ll notice that there is no ‘run’ button or anything similar to it.

What there is, however, is a possibility to run a ‘task’. It might be best explained on the official documentation:

Lots of tools exist to automate tasks like building, packaging, testing or deploying software systems. Examples include Make, Ant, Gulp, Jake, Rake and MSBuild.

These tools are mostly run from the command line and automate jobs outside the inner software development loop (edit, compile, test and debug). Given their importance in the development lifecycle, it is very helpful to be able run them and analyze their results from within VS Code.

Here you can use whichever you like most (and is appropriate). I personally decided on Gulp for no particular reason: it’s a funny word and I vaguely recall using it in a class some time ago.

Running a task

In order to start a task (which in our scenario will consist of simply firing up our browser with the app we’re creating), you have to search for it. In VS Code, pres the key combination [Ctrl] + [Shift] + [P]. If you now search for ‘run task’, you will notice that it gives you the option to choose “Tasks: Run Task”, but with nothing to select from the dropdown menu.

In order to create our task, we have to get started with Gulp first. With Gulp we will define our task after which it will be available to us in the beforementioned dropdown menu.

Initializing package.json

Package.json is essentially your npm configuration. It contains metadata about your application like name, version, author as well as dependencies, files, etc. You could do without it but that would mean our dependencies wouldn’t be saved along with the application (and I do like that)!

In order to do so, issue the following commands:

You will now have to enter some information to setup the package.json file and after that we can get started (and finished) with Gulp.

Installing Gulp

We need two Gulp-related packages to do what we want it to do: Gulp and Gulp-Open. The first one will provide the general Gulp environment while the second one will provide a way for us to open the browser.

The following commands will install these packages:

Setting up gulpfile.js

Now it’s time to create our Task. In order to do so, go to your project’s root folder (in my case: \Examples\) and create a new file called gulpfile.js.

Afterwards, add the following contents:

What it does is simple: create a new task called ‘default’ and make it open the app.html file. This will prompt you for the default program to open .html files with (if you didn’t have that set already) and subsequently open it with that program.

Launching the browser

The last step is simply executing the given task. You have two options here: either you use the beforementioned [Ctrl] + [Shift] + [P] method which will spawn a second window with some console output, or you simply enter $ gulp in the command prompt at the location of your gulpfile.

This will give you an output that resembles this


and also opens app.html in your favorite browser.

Share on Facebook0Tweet about this on Twitter0Share on LinkedIn0Share on TumblrShare on Google+0Share on Reddit0Flattr the authorDigg this

2 thoughts on “Launching your first webapp in Visual Studio Code through Gulp”

Leave a Reply

Your email address will not be published. Required fields are marked *