I am new to Angular 2. I am confused with how Angular 2 works in production environment.
What are the prerequisites for running Angular 2 application in production server?
Is it possible to deploy the application in IIS server or is node server required?
After compiling the file in development machine using node, do we need to deploy both .js and .ts to production?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With