I am playing around with Angular2 in combination with ASP.NET5, gulp and typescript. Everything works fine when I solve the tutorials for Angular, but I am not sure how to setup the process in combination with ASP.NET 5.
I made a project with working typescript compilation and bundling and I now the issues are starting:
When I add the tsConfig file to the root of the project, visual studio does not recognizes the file. When I place it to wwwroot/scripts everything is fine (very strange).
Angular2 does not support DefinityTyped anymore, the file is empty and contains the hint that I must install the npm package. I did it but there are so many files. Which type definitions do I have to include? None of them work. I always get the error that it cannot find angular2/angular2.
It is very strange. When I use commonjs for typescript the compilation works. I am really confused because I dont understand how the include works. Resharper shows a lot of errors but when I can disable it for the moment.
The Angular2 NPM Package also contains the script files. But because of the fact that they are outside I cannot reference them directly. I cannot find a bower package with the scripts and it also make no sense to have the package twice.
I would be quite happy about a tutorial or some best practices how to setup angular2 with asp.net 5.
By the way: There are so many package managers: NPM, NuGet, gulp, tsd...
In relation to point #4, I believe that there are no plans to produce a Bower package for angular2 (see https://github.com/angular/angular/issues/4018). This seems likely to cause some friction with Visual Studio 2015 ASP.NET 5 template projects which are set up to use Bower for client-side packages (see http://docs.asp.net/en/latest/client-side/bower.html).
I have worked around this as follows:
npm install --save angular2
Configure a gulp task to copy relevant files from the
node_modules
directory structure to thewwwroot\lib
directory structure. This could be done as follows ingulpfile.js
:I agree, it is somewhat bewildering at first to get Angular2 up and running in the Visual Studio Asp.net 5 environment. I put the typescript files associated with my Angular2 app in a folder on the root called App (capital "A") and then use gulp to transpile into javascript into the "app" (small "a") at "./wwwroot/app". The tsconfig.json file seems to function okay in the App folder and it looks like the following:
My gulp task looks like the following (note that I also need to copy any associated HTML views and JSON files to the app folder as well):
Now when I run the gulp task compile:ts my app folder gets all the proper assets.
Now, I realize you probably do not want to hear about yet another package manger, but I recommend you consider using JSPM. Built by the same team that built system.js, JSPM really excels in bundling your Angular2 app for production. JSPM requires that you have a config.json file in your root and mine (configured to tell JSPM where the angular2 dev dependencies are) is as follows:
The I use a gulp-jspm to execute the bundling into on self-contained js file:
Then into your index.html file you have one nice tidy script reference:
When I build for production I change the BundleVersion variable as a cache buster.