Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy Angular 2 application developed in Typescript to production?

Tags:

angular

I am new to Angular 2. I am confused with how Angular 2 works in production environment.

  1. What are the prerequisites for running Angular 2 application in production server?

  2. Is it possible to deploy the application in IIS server or is node server required?

  3. After compiling the file in development machine using node, do we need to deploy both .js and .ts to production?

like image 870
Jijil PK Avatar asked Dec 22 '15 02:12

Jijil PK


People also ask

Does angular 2 use TypeScript?

Angular 2 is built on TypeScript, which uses ES6 syntax and compiles to vanilla JavaScript. Standard ES5 JavaScript is also valid TypeScript, so you can still use your existing code. Where TypeScript differs is in the typing system. Although it is optional, I recommend you use the typing system in your projects.


1 Answers

I use JSPM to make my angular2 projects production ready. Other popular tools like JSPM include webpack, and browserfy. One of the important tasks that JSPM will accomplish is to bundle the various modules that make up your angular2 project. I also set the "selfExecutingBundle" flag to true and have JSPM make one bundled js file (e.g. myApp.bundled.js) and from there I minify it (myApp.bundled.min.js) and this one script reference is used in the index.html file.

<html>    <head>      <title>Hello Angular World</title>  </head>  <body>  <div>      <my-app>Loading...</my-app>  </div>      <script src="/js/myApp.bundle.min.js"></script>  </body>    </html>

And that is all you need!

In the future when the HTTP/2 spec is more common, there may be less of a need to bundle your module-based projects, but for now I think bundling is needed.

There is no reference to your typescript files (as they were already transpiled in the process of making the myApp.bundled.js). As Zama said, you can run angular2 on any server (I use IIS and works fine).

UPDATE: Since the final release of Angular 2, I have switched to using the angular-cli for building for production. Setup is easy (no spaghetti of gulp tasks) and the final bundle is super-optimized (esp due to tree-shaking). I recommend checking out the angular-cli for setting up, developing with, and building your ng2 projects.

like image 169
brando Avatar answered Sep 18 '22 09:09

brando