« Back to News

Way to scaffold and deploy Angular2

This article is intended for the developers who want to get their hands on Angular2 without waiting for a stable version. Scaffold an Angular2 app with this Yeoman generator, and deploy it easily on Heroku.

While Angular has been a strictly opinionated framework of JavaScript, it has always been quite un-opinionated about how you structure your application and how you deploy it. Being un-opinionated about the project structure and deployment strategy is both good and bad. Good, because it lets you decide how you arrange (MVC or based on features) your code and where to deploy it. Bad, because it becomes quite confusing for beginners to decide which of the many ways to structure and deploy angular applications.

With Angular2 framework development reaching Release Candidate milestone, developers have already started trying out the latest builds to get used to it. Also, TypeScript is being considered as the recommended language for Angular2, adding one extra step (compilation) in the development process. I have checked out Angular2 quickstart project & angular-cli. Although the boilerplate is quite self-sufficient, it still lacks the same stuff as Angular: structure and deployment. Playing around with the quickstart project was good, but I wanted to check out the complete flow of developing, testing and deploying an Angular2 app and make the process as easy as possible until we have a stable build of Angular2 with some official guidance from its creators.

I have created a Yeoman Generator (listed on Yeoman.io, named ‘angular2-sass-gulp-heroku’), which creates the boilerplate for a simple Angular2 app. This structure is similar to what is generated by angular-cli. The resulting application uses all the commands provided by the cli along with a few tweaks which have been added to include SASS and Bootstrap SASS.

Moreover, I have added steps to deploy the generated application on Heroku without any extra dependencies, just using the modules which are already in the project.

Below, I will explain how to use this generator to get a fully working Angular2 startup app with:

  • A folder structure to arrange your TypeScript code neatly
  • Gulp tasks to clean and move static font files within build
  • SASS (SCSS syntax) & Bootstrap SASS support (Javascript library of Bootstrap included)
  • Minor tweaks for Heroku deployment

Prerequisites

  • Node.js (version >= 4)
  • Git installed on your development machine
  • Heroku account & Heroku Toolbelt installed. Log in to Heroku using Heroku toolbelt on your terminal/CMD prompt.

Install global dependencies

Run these commands to globally install angular-cli, Yeoman & the app generator:

npm install -g angular-cli
npm install -g yo
npm install -g generator-angular2-sass-gulp-heroku

Generate the project

I will be using test-project as project name.

Run:

yo angular2-sass-gulp-heroku test-project

The generator will ask following details:

  1. Project name
  2. Small description of the project
  3. Github URL(if any) of the project

Once you fill in these details, the project will be created in the directory where you executed the above command.

Change to the project directory now.

cd test-project

Comments are closed.

About the Writer

  • Tushar Chauhan
    Lead Software Developer at Synerzip

How can Synerzip Help You?

By partnering with Synerzip, clients rapidly scale their engineering team, decrease time to market and save at least 50 percent with our Agile development teams in India.