Quickstart: Angular2 with TypeScript and Gulp

Angular2 is around the corner. The new version of the framework is much simpler to learn thanks to easier and more concise concepts like component-based architecture, new dependency injection or built-in modularity. In this step-by-step tutorial you will learn how how to get started with Angular2 with TypeScript and Gulp. Source code available on Github.


Angular 1.x is probably still the most popular Front-end framework these days and there is no doubt Angular 1.x is a great framework. However it is incredibly difficult to master. The complex API and many concepts introduced since its launch make understanding the framework and thus using it effectively really hard.

Angular2, on the other hand, is a new opening. The new version of the framework is much simpler to learn thanks to easier and more concise concepts like component-based architecture, new dependency injection or built-in modularity.

If you want to practice and start learning Angular2 there is no better place than But if you are looking for the ways of utilizing Angular2 with Gulp – this tutorial is for you.

Note: The source code for this article can be found on Github: I assume the repository gets updated quite often.

Project layout

The initial project is based on the Angular2 Quickstart: with some changes. The most important change is to separate source files from build files: src directory contains all the source files and build contains all compiled and processed files. The server uses build directory as a base directory to serve content.

|   .gitignore
|   bs-config.json  -> BrowserSync configuration
|   gulpfile.ts     -> Gulp in TypeScript
|   package.json    -> npm configuration
|   tsconfig.json   -> TypeScript configuration
|   typings.json    -> TypeScript typings definitions
    |   index.html  -> Starting point for the application
    \---app         -> Application modules
            app.component.ts -> Main application component
            app.html         -> Main application template
            main.ts          -> Application bootstrap

The script for creating directory structure:

mkdir angular2-typescript-gulp\src\app
cd angular2-typescript-gulp
touch .gitignore bs-config.json gulpfile.ts package.json tsconfig.json typings.json
cd src
touch index.html
cd app
touch app.component.ts app.html main.ts

NPM global dependencies

Assuming node and npm is already installed, you may install global dependencies by invoking the following command:

npm i -g <dependency>

Required global dependencies in order to run the project:

  • gulp and gulp-cli (3.9.1)
  • typings (0.6.8)
  • typescript (1.8.2)
  • ts-node (0.5.5)

TypeScript confguration – tsconfig.ts

Compiled files will be saved intto build/app. Please note that gulpfile.ts is excluded from the compilation.

  "compilerOptions": {
    "outDir": "build/app",
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  "exclude": [

Note: If you import your project to IDE (e.g. IntelliJ) let the IDE use this file too.

Typings – typings.json

To get started we need only one definition run the following command:

typings install es6-shim –ambient –save

which will append the following content to typings.json

  "ambientDependencies": {
    "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c"

Typings will be download to typings directory and they will be downloaded on npm install.

npm configuration – package.json

  "name": "angular2-typescript-gulp",
  "version": "1.0.0",
  "description": "Angular2 with TypeScript and Gulp QuickStart",
  "scripts": {
    "clean": "gulp clean",
    "compile": "gulp compile",
    "build": "gulp build",
    "server": "lite-server",
    "postinstall": "typings install"
  "repository": {
    "type": "git",
    "url": ""
  "author": "Rafał Borowiec",
  "license": "MIT",
  "bugs": {
    "url": ""
  "dependencies": {
    "angular2": "2.0.0-beta.7",
    "systemjs": "0.19.22",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.2",
    "zone.js": "0.5.15"
  "devDependencies": {
    "concurrently": "^2.0.0",
    "del": "^2.2.0",
    "gulp": "^3.9.1",
    "gulp-typescript": "^2.12.0",
    "gulp-sourcemaps": "^1.6.0",
    "lite-server": "^2.1.0",
    "typescript": "^1.8.2",
    "typings": "^0.6.8"

A word about scripts:

  • clean – removes build directory
  • compile – TypeScript compilation (with sourcemaps)
  • build – build the project
  • server – runs lite server which uses configuration from bs-config.json

BrowserSync configuration (lite-server)

By default the content is served from the current directory so this needs to be changed. And since Lite Server uses BrowserSync it enough to provide bs-config.json that configures the server to serve content from build directory.

  "port": 8000,
  "files": [
  "server": {
    "baseDir": "build"

Building the project with Gulp

To get started we need a task(s) that compiles TypeScript files, copies assets and dependencies to a build directory. Several tasks are needed in order to achieve it.

var gulp = require("gulp");
var del = require("del");
var tsc = require("gulp-typescript");
var sourcemaps  = require('gulp-sourcemaps');
var tsProject = tsc.createProject("tsconfig.json");

 * Remove build directory.
gulp.task('clean', (cb) => {
    return del(["build"], cb);

 * Compile TypeScript sources and create sourcemaps in build directory.
gulp.task("compile", () => {
    var tsResult = gulp.src("src/**/*.ts")
    return tsResult.js

 * Copy all resources that are not TypeScript files into build directory.
gulp.task("resources", () => {
    return gulp.src(["src/**/*", "!**/*.ts"])

 * Copy all required libraries into build directory.
gulp.task("libs", () => {
    return gulp.src([
        ], {cwd: "node_modules/**"}) /* Glob required here. */

 * Build the project.
gulp.task("build", ['compile', 'resources', 'libs'], () => {
    console.log("Building the project ...")

Installing dependencies and checking the build

It is a high time to install all dependencies. Run:

npm install

node_modules and typings directories should be created during the install.

Build the project:

npm run clean & npm run build

build directory should be created during the build

|   index.html                       
|       app.component.js       
|       app.html                     
|       main.js                      
    |   \---bundles                  
    |           angular2-polyfills.js
    |       es6-shim.min.js          
    |   \---bundles                  
    |           Rx.js                

Run the server:

npm run server

The empty page should be displayed in the browser.

Creating the application

All the basic infrastucture is in place. It is a high time to create the application.


import {Component} from "angular2/core";
import {OnInit} from "angular2/core";

    selector: "app",
    templateUrl: "./app/app.html"
export class AppComponent implements OnInit {

    ngOnInit() {
        console.log("Application component initialized ...");


<p>Angular 2 is running ... </p>


import {bootstrap} from "angular2/platform/browser";
import {AppComponent} from "./app.component";



The libraries are reference from lib directory that is created during the build task.

    <title>Angular 2 TypeScript Gulp QuickStart</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- 1. Load libraries -->
    <!-- IE required polyfills, in this exact order -->
    <script src="lib/es6-shim/es6-shim.min.js"></script>
    <script src="lib/systemjs/dist/system-polyfills.js"></script>

    <script src="lib/angular2/bundles/angular2-polyfills.js"></script>
    <script src="lib/systemjs/dist/system.src.js"></script>
    <script src="lib/rxjs/bundles/Rx.js"></script>
    <script src="lib/angular2/bundles/"></script>

    <!-- 2. Configure SystemJS -->
            packages: {
                app: {
                    format: 'register',
                    defaultExtension: 'js'
                .then(null, console.error.bind(console));


<!-- 3. Display the application -->


Building and running

npm run clean & npm run build
npm run server

Notes on IntelliJ

IntelliJ handles the proposed setup with no problem. If TypeScript compiler is used in IntelliJ it should use the project’s tsconfig.json. In such case, changes to ts files will be reflected in build directory immediately.

Source code

What’s next?

Much more is needed to make real use of this project. Therefore more features will be added soon. If you have any suggestion, comment or add Github issues.


If you need more mature starter, have a look at angular2-seed project angular2-seed uses gulp in much more advanced way and it is already supporting production and development build, unit and integration tests and many more.

Reference: Quickstart: Angular2 with TypeScript and Gulp from our WCG partner Rafal Borowiec at the blog.

Rafal Borowiec

Rafal is an IT specialist with about 8 years of commercial experience, specializing in software testing and quality assurance, software development, project management and team leadership. He is currently holding a position of a Team Leader at Goyello where he is mainly responsible for building and managing teams of professional developers and testers. He is also responsible for maintaining relations with customers and acquiring new ones, mainly through consultancy. He believes in Agile project management and he is a big fan of technology, especially Java related (but not limited too). He likes sharing knowledge about software development and practices, through his blog ( and Twitter (@kolorobot) but also on internal and external events like conferences or workshops.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Back to top button