A faster alternative using scaffolding tools

In the latest few paragraphs, we basically built our very own server-side and client-side environment by configuring everything manually. Truth be told, what we just did is neither the quickest nor the most effective way to start a project involving a client-side framework such as Angular 2, as a matter of fact, we could achieve the same results in a fraction of the time we just spent by using the ASP.NET Core project scaffolding tools such as Yeoman, which are available through NPM, together with a proper generator template such as aspnetcore-spa.

Not only will these tools generate a fully-functional ASP.NET Core and Angular 2 boilerplate, much like the one we just made, they'll also take care of a number of issues beforehand that we would otherwise have to manually set up later. These include server-side pre-rendering, efficient cache management, optimized production builds, and much more. On top of that, they can be easily enhanced with other helper packages such as WebPack and JavaScriptServices, a great set of tools and middlewares for building SPA projects with ASP.NET Core and Angular 2.

The reasons to say no (not yet)

All of this sounds so exciting that we may well ask ourselves why in the world didn't we go for that?

The reason is simple, what we just made, together with a lot of things we'll assemble during the course of the following chapters, is also part of our learning process. In other words, this is why we're reading this book instead of just copying some working samples from a bunch of web pages, or GitHub projects, and putting them together. This doesn't mean we don't have to use Yeoman, as a matter of fact, we will be using it, together with a lot of other great tools that will speed up our development and help us to write better code. Eventually, just not on our first run, that's for sure. We don't want our journey to be spoiled, do we?

A quick scaffolding sample

However, it's also true that taking a look at these tools, and eventually being able to properly use them, can easily be seen as part of our learning process. If you want to do that, you need to have Node.js installed, unless you prefer to use what's bundled with Visual Studio 2015.

Open a command prompt with administrative rights and navigate through theNode.js installation folder. If you're using the one shipped with VS2015 it should be something like the following:  C:Program Files (x86)Microsoft Visual Studio 14.0WebExternal.

If you went for a new install, it should be the following (for x64 architectures):  C:Program FilesNodejs.

Once there, type the following command and execute it to update NPM to the latest version:

npm install npm -g

Then type and execute the following to install Yeoman together with the aspnetcore-spa generator:

npm install -g yo generator-aspnetcore-spa

Finally, type and execute the following commands to create your application's entry point:

cd C:ProjectsYour-SPA-folder 
yo aspnetcore-spa

That's about it. For further reference regarding how to use Yeoman, it's strongly advisable to take a look at the official documentation at the following URL:  http://yeoman.io/learning/.

If you're bold enough to also install WebPack and JavaScriptServices, you should definitely read the ASP.NET Core JavaScript Services official documentation, written by Steve Sanderson, who is the author of the JavaScriptServices project and the KnockoutJs library, as well as being a Microsoft employee:  https://github.com/aspnet/JavaScriptServices#javascriptservices.

Note

Before moving forward, it's very important to understand the fact that we will not cover these packages throughout the book. We will take it for granted that we don't have these features available, so we will often spend some time designing and building our own implementation. That's why we don't suggest that you do that during the first reading.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset