dans Non classé

How to deploy an Angular2 app on your favorite PaaS

You know it, I became a PaaS fan for several reasons : end of server management, end of everything management (backups, logs, monitoring, auto-scaling …). It allows me to concentrate on what really matter : delivering features often & quickly to my business.

Today, I’d like to share with you how to deploy an Angular2 app on your favorite PaaS (Clever-Cloud, Heroku or whatever).

Long story short: build sources in order to generate static files, serve them with an Express server.

I – Update codebase

  • Edit package.json

ng build command generates static file in dist/ folder. ng is available with angular-cli, this is why it must be added to dependencies.

Obviously, node & npm versions should be indicated in order to avoid surprises between your local dev environment & remote environment.

  • Create server.js

This code creates a tiny express app which will serve static files in dist/ folder.

II – Deploy 🙂

 

  • Initialize a Git repo & commit

Don’t forget to create a .gitignore file if it does not exist because it is not necessary to commit node_modules/ folder & Co.

Heroku

Install Heroku CLI & execute :

You should now be able to follow deployment. Don’t hesitate to use heroku logs for further informations.

Clever-Cloud

Install Clever-Cloud CLI & execute :

You should now be able to follow deployment.

Conclusion

Deploying an Angular2 app on a PaaS is very simple & fast.

I’m a little bit confusing with JS ecosystem because I started to learn Angular2 & JS & TS last week. Don’t hesitate to share with me your tips & tricks, I’ll keep this article updated.

 

Sources :

Ecrire un Commentaire

Commenter