Create An Aurelia Single Page Application In ASP.NET Core 1.0

Introduction
 
In our previous article, we studied How to configure Aurelia Single Page applications in ASP.NET Core 1.0. Now, we are going to create Aurelia single page Applications in ASP.NET Core 1.0. 
 
Aurelia 
 
Aurelia is a JavaScript client framework for mobile, desktop, Web and we can create a single page applications using th Aurelia framework.
 
Configuring Aurelia in ASP.NET Core 1.0 
 
In our previous article, we mentioned a detailed description about How to configure Aurelia Single Page applications in ASP.NET Core 1.0. Thus, we only noticed the important steps of Aurelia configuration in ASP.NET Core 1.0. Install jspm and Aurelia framework through the command. 
  • Download and install : Node.js
  • Download and install : Git - Downloads 
  • Install jspm [ Command : "npm install -g jspm" ].
  • jspm Initialization [ Command : "jspm init" ].
  • Install Aurelia framework in ASP.NET Core 1.0 [ Command : "jspm install aurelia-framework" ].
  • Install Aurelia bootstrapper in ASP.NET Core 1.0 [ Command : "jspm install aurelia-bootstrapper" ].
Project Structure
 
Click "show all files icon" in Solution Explorer. You can see the jspm_packages reference and config.js inside the wwwroot. 
 
 
 
Aurelia Reference in index.html page 
 
We are going to add Aurelia references in "index.html" page because in ASP.NET Core 1.0, we run index.html file as a start page in default. Don't worry. We can mention other pages also but we need to do some customization in the code.
 
Index.html 
 
The code given below contains the reference of "jspm_packages/system.js" & "config.js". The body tag contains the "aurelia-app" or an entry point of Aurelia app and it automatically detects the app.js file in our root folder (what we mention baseURL on jspm installation) or wwwroot. The "System.import("Aurelia-Bootstrapper")" will help to import Aurelia-Bootstrapper references in the body. 
 
 
 
config.js 
 
JSON file contains all the details about Aurelia configuration.
  1. System.config({  
  2.   baseURL: "/",  
  3.   defaultJSExtensions: true,  
  4.   transpiler: "babel",  
  5.   babelOptions: {  
  6.     "optional": [  
  7.       "runtime",  
  8.       "optimisation.modules.system"  
  9.     ]  
  10.   },  
  11.   paths: {  
  12.     "github:*""jspm_packages/github/*",  
  13.     "npm:*""jspm_packages/npm/*"  
  14.   },  
  15.    
  16.   map: {  
  17.     "aurelia-bootstrapper""npm:aurelia-bootstrapper@2.0.1",  
  18.     "aurelia-framework""npm:aurelia-framework@1.0.8",  
  19.     "aurelia-pal-browser""npm:aurelia-pal-browser@1.1.0",  
  20.     "babel""npm:babel-core@5.8.38",  
  21.     "babel-runtime""npm:babel-runtime@5.8.38",  
  22.     "core-js""npm:core-js@1.2.7",  
  23.     "github:jspm/nodelibs-assert@0.1.0": {  
  24.       "assert""npm:assert@1.4.1"  
  25.     },  
  26.     "github:jspm/nodelibs-buffer@0.1.0": {  
  27.       "buffer""npm:buffer@3.6.0"  
  28.     },  
  29.     "github:jspm/nodelibs-path@0.1.0": {  
  30.       "path-browserify""npm:path-browserify@0.0.0"  
  31.     },  
  32.     "github:jspm/nodelibs-process@0.1.2": {  
  33.       "process""npm:process@0.11.9"  
  34.     },  
  35.     "github:jspm/nodelibs-util@0.1.0": {  
  36.       "util""npm:util@0.10.3"  
  37.     },  
  38.     "github:jspm/nodelibs-vm@0.1.0": {  
  39.       "vm-browserify""npm:vm-browserify@0.0.4"  
  40.     },  
  41.     "npm:assert@1.4.1": {  
  42.       "assert""github:jspm/nodelibs-assert@0.1.0",  
  43.       "buffer""github:jspm/nodelibs-buffer@0.1.0",  
  44.       "process""github:jspm/nodelibs-process@0.1.2",  
  45.       "util""npm:util@0.10.3"  
  46.     },  
  47.     "npm:aurelia-binding@1.1.1": {  
  48.       "aurelia-logging""npm:aurelia-logging@1.2.0",  
  49.       "aurelia-metadata""npm:aurelia-metadata@1.0.3",  
  50.       "aurelia-pal""npm:aurelia-pal@1.2.0",  
  51.       "aurelia-task-queue""npm:aurelia-task-queue@1.1.0"  
  52.     },  
  53.     "npm:aurelia-bootstrapper@2.0.1": {  
  54.       "aurelia-event-aggregator""npm:aurelia-event-aggregator@1.0.1",  
  55.       "aurelia-framework""npm:aurelia-framework@1.0.8",  
  56.       "aurelia-history""npm:aurelia-history@1.0.0",  
  57.       "aurelia-history-browser""npm:aurelia-history-browser@1.0.0",  
  58.       "aurelia-loader-default""npm:aurelia-loader-default@1.0.0",  
  59.       "aurelia-logging-console""npm:aurelia-logging-console@1.0.0",  
  60.       "aurelia-pal""npm:aurelia-pal@1.2.0",  
  61.       "aurelia-pal-browser""npm:aurelia-pal-browser@1.1.0",  
  62.       "aurelia-polyfills""npm:aurelia-polyfills@1.1.1",  
  63.       "aurelia-router""npm:aurelia-router@1.1.1",  
  64.       "aurelia-templating""npm:aurelia-templating@1.2.0",  
  65.       "aurelia-templating-binding""npm:aurelia-templating-binding@1.2.0",  
  66.       "aurelia-templating-resources""npm:aurelia-templating-resources@1.2.0",  
  67.       "aurelia-templating-router""npm:aurelia-templating-router@1.0.1"  
  68.     },  
  69.     "npm:aurelia-dependency-injection@1.3.0": {  
  70.       "aurelia-metadata""npm:aurelia-metadata@1.0.3",  
  71.       "aurelia-pal""npm:aurelia-pal@1.2.0"  
  72.     },  
  73.     "npm:aurelia-event-aggregator@1.0.1": {  
  74.       "aurelia-logging""npm:aurelia-logging@1.2.0"  
  75.     },  
  76.     "npm:aurelia-framework@1.0.8": {  
  77.       "aurelia-binding""npm:aurelia-binding@1.1.1",  
  78.       "aurelia-dependency-injection""npm:aurelia-dependency-injection@1.3.0",  
  79.       "aurelia-loader""npm:aurelia-loader@1.0.0",  
  80.       "aurelia-logging""npm:aurelia-logging@1.2.0",  
  81.       "aurelia-metadata""npm:aurelia-metadata@1.0.3",  
  82.       "aurelia-pal""npm:aurelia-pal@1.2.0",  
  83.       "aurelia-path""npm:aurelia-path@1.1.1",  
  84.       "aurelia-task-queue""npm:aurelia-task-queue@1.1.0",  
  85.       "aurelia-templating""npm:aurelia-templating@1.2.0"  
  86.     },  
  87.     "npm:aurelia-history-browser@1.0.0": {  
  88.       "aurelia-history""npm:aurelia-history@1.0.0",  
  89.       "aurelia-pal""npm:aurelia-pal@1.2.0"  
  90.     },  
  91.     "npm:aurelia-loader-default@1.0.0": {  
  92.       "aurelia-loader""npm:aurelia-loader@1.0.0",  
  93.       "aurelia-metadata""npm:aurelia-metadata@1.0.3",  
  94.       "aurelia-pal""npm:aurelia-pal@1.2.0"  
  95.     },  
  96.     "npm:aurelia-loader@1.0.0": {  
  97.       "aurelia-metadata""npm:aurelia-metadata@1.0.3",  
  98.       "aurelia-path""npm:aurelia-path@1.1.1"  
  99.     },  
  100.     "npm:aurelia-logging-console@1.0.0": {  
  101.       "aurelia-logging""npm:aurelia-logging@1.2.0"  
  102.     },  
  103.     "npm:aurelia-metadata@1.0.3": {  
  104.       "aurelia-pal""npm:aurelia-pal@1.2.0"  
  105.     },  
  106.     "npm:aurelia-pal-browser@1.1.0": {  
  107.       "aurelia-pal""npm:aurelia-pal@1.2.0"  
  108.     },  
  109.     "npm:aurelia-polyfills@1.1.1": {  
  110.       "aurelia-pal""npm:aurelia-pal@1.2.0"  
  111.     },  
  112.     "npm:aurelia-route-recognizer@1.1.0": {  
  113.       "aurelia-path""npm:aurelia-path@1.1.1"  
  114.     },  
  115.     "npm:aurelia-router@1.1.1": {  
  116.       "aurelia-dependency-injection""npm:aurelia-dependency-injection@1.3.0",  
  117.       "aurelia-event-aggregator""npm:aurelia-event-aggregator@1.0.1",  
  118.       "aurelia-history""npm:aurelia-history@1.0.0",  
  119.       "aurelia-logging""npm:aurelia-logging@1.2.0",  
  120.       "aurelia-path""npm:aurelia-path@1.1.1",  
  121.       "aurelia-route-recognizer""npm:aurelia-route-recognizer@1.1.0"  
  122.     },  
  123.     "npm:aurelia-task-queue@1.1.0": {  
  124.       "aurelia-pal""npm:aurelia-pal@1.2.0"  
  125.     },  
  126.     "npm:aurelia-templating-binding@1.2.0": {  
  127.       "aurelia-binding""npm:aurelia-binding@1.1.1",  
  128.       "aurelia-logging""npm:aurelia-logging@1.2.0",  
  129.       "aurelia-templating""npm:aurelia-templating@1.2.0"  
  130.     },  
  131.     "npm:aurelia-templating-resources@1.2.0": {  
  132.       "aurelia-binding""npm:aurelia-binding@1.1.1",  
  133.       "aurelia-dependency-injection""npm:aurelia-dependency-injection@1.3.0",  
  134.       "aurelia-loader""npm:aurelia-loader@1.0.0",  
  135.       "aurelia-logging""npm:aurelia-logging@1.2.0",  
  136.       "aurelia-metadata""npm:aurelia-metadata@1.0.3",  
  137.       "aurelia-pal""npm:aurelia-pal@1.2.0",  
  138.       "aurelia-path""npm:aurelia-path@1.1.1",  
  139.       "aurelia-task-queue""npm:aurelia-task-queue@1.1.0",  
  140.       "aurelia-templating""npm:aurelia-templating@1.2.0"  
  141.     },  
  142.     "npm:aurelia-templating-router@1.0.1": {  
  143.       "aurelia-binding""npm:aurelia-binding@1.1.1",  
  144.       "aurelia-dependency-injection""npm:aurelia-dependency-injection@1.3.0",  
  145.       "aurelia-logging""npm:aurelia-logging@1.2.0",  
  146.       "aurelia-metadata""npm:aurelia-metadata@1.0.3",  
  147.       "aurelia-pal""npm:aurelia-pal@1.2.0",  
  148.       "aurelia-path""npm:aurelia-path@1.1.1",  
  149.       "aurelia-router""npm:aurelia-router@1.1.1",  
  150.       "aurelia-templating""npm:aurelia-templating@1.2.0"  
  151.     },  
  152.     "npm:aurelia-templating@1.2.0": {  
  153.       "aurelia-binding""npm:aurelia-binding@1.1.1",  
  154.       "aurelia-dependency-injection""npm:aurelia-dependency-injection@1.3.0",  
  155.       "aurelia-loader""npm:aurelia-loader@1.0.0",  
  156.       "aurelia-logging""npm:aurelia-logging@1.2.0",  
  157.       "aurelia-metadata""npm:aurelia-metadata@1.0.3",  
  158.       "aurelia-pal""npm:aurelia-pal@1.2.0",  
  159.       "aurelia-path""npm:aurelia-path@1.1.1",  
  160.       "aurelia-task-queue""npm:aurelia-task-queue@1.1.0"  
  161.     },  
  162.     "npm:babel-runtime@5.8.38": {  
  163.       "process""github:jspm/nodelibs-process@0.1.2"  
  164.     },  
  165.     "npm:buffer@3.6.0": {  
  166.       "base64-js""npm:base64-js@0.0.8",  
  167.       "child_process""github:jspm/nodelibs-child_process@0.1.0",  
  168.       "fs""github:jspm/nodelibs-fs@0.1.2",  
  169.       "ieee754""npm:ieee754@1.1.8",  
  170.       "isarray""npm:isarray@1.0.0",  
  171.       "process""github:jspm/nodelibs-process@0.1.2"  
  172.     },  
  173.     "npm:core-js@1.2.7": {  
  174.       "fs""github:jspm/nodelibs-fs@0.1.2",  
  175.       "path""github:jspm/nodelibs-path@0.1.0",  
  176.       "process""github:jspm/nodelibs-process@0.1.2",  
  177.       "systemjs-json""github:systemjs/plugin-json@0.1.2"  
  178.     },  
  179.     "npm:inherits@2.0.1": {  
  180.       "util""github:jspm/nodelibs-util@0.1.0"  
  181.     },  
  182.     "npm:path-browserify@0.0.0": {  
  183.       "process""github:jspm/nodelibs-process@0.1.2"  
  184.     },  
  185.     "npm:process@0.11.9": {  
  186.       "assert""github:jspm/nodelibs-assert@0.1.0",  
  187.       "fs""github:jspm/nodelibs-fs@0.1.2",  
  188.       "vm""github:jspm/nodelibs-vm@0.1.0"  
  189.     },  
  190.     "npm:util@0.10.3": {  
  191.       "inherits""npm:inherits@2.0.1",  
  192.       "process""github:jspm/nodelibs-process@0.1.2"  
  193.     },  
  194.     "npm:vm-browserify@0.0.4": {  
  195.       "indexof""npm:indexof@0.0.1"  
  196.     }  
  197.   }  
  198. });  
package.json 
 
JSON file contains all the dependencies of Aurelia.
  1. {  
  2.   "jspm": {  
  3.     "directories": {  
  4.       "baseURL""wwwroot"  
  5.     },  
  6.     "dependencies": {  
  7.       "aurelia-bootstrapper""npm:aurelia-bootstrapper@^2.0.1",  
  8.       "aurelia-framework""npm:aurelia-framework@^1.0.8",  
  9.       "aurelia-pal-browser""npm:aurelia-pal-browser@^1.1.0"  
  10.     },  
  11.     "devDependencies": {  
  12.       "babel""npm:babel-core@^5.8.24",  
  13.       "babel-runtime""npm:babel-runtime@^5.8.24",  
  14.       "core-js""npm:core-js@^1.1.4"  
  15.     }  
  16.   }  
  17. }  
app.js
 
We have created one more staticfile or app.js inside the wwwroot or Webroot. The file given below contains the syntax as "export". It will help to export the entire class details to correspondence app.html as Controller and View name relation in ASP.NET MVC. 
  1. export class App  
  2. {  
  3.     constructor()  
  4.     {  
  5.         this.Message = "Aurelia in Asp.Net Core 1.0 !!";  
  6.     }  
  7. }  
app.html
 
Now, we are going to create one more HTML file inside the wwwroot or Webroot. Here, we will bind the app.js methods,functions etc. inside the curly bracket "${}"
  1. <template>  
  2. <div>${Message}</div>  
  3. </template>  
Project.json
 
When we want to call Staticfiles in ASP.NET Core 1.0, we need to add Staticfiles dependency in project.json.
  1. {  
  2.   "dependencies": {  
  3.     "Microsoft.NETCore.App": {  
  4.       "version""1.0.1",  
  5.       "type""platform"  
  6.     },  
  7.     "Microsoft.AspNetCore.Diagnostics""1.0.0",  
  8.     "Microsoft.AspNetCore.Server.IISIntegration""1.0.0",  
  9.     "Microsoft.AspNetCore.Server.Kestrel""1.0.1",  
  10.     "Microsoft.Extensions.Logging.Console""1.0.0",  
  11.     "Microsoft.AspNetCore.StaticFiles""1.1.0"  
  12.   },  
  13.    
  14.   "tools": {  
  15.     "Microsoft.AspNetCore.Server.IISIntegration.Tools""1.0.0-preview2-final"  
  16.   },  
  17.    
  18.   "frameworks": {  
  19.     "netcoreapp1.0": {  
  20.       "imports": [  
  21.         "dotnet5.6",  
  22.         "portable-net45+win8"  
  23.       ]  
  24.     }  
  25.   },  
  26.    
  27.   "buildOptions": {  
  28.     "emitEntryPoint"true,  
  29.     "preserveCompilationContext"true  
  30.   },  
  31.    
  32.   "runtimeOptions": {  
  33.     "configProperties": {  
  34.       "System.GC.Server"true  
  35.     }  
  36.   },  
  37.    
  38.   "publishOptions": {  
  39.     "include": [  
  40.       "wwwroot",  
  41.       "web.config"  
  42.     ]  
  43.   },  
  44.    
  45.   "scripts": {  
  46.     "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]  
  47.   }  
  48. }  
Configuration in Startup.cs Class
 
The code given below in UseFileServer() will help to call staticfiles in ASP.NET Core 1.0. 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Threading.Tasks;  
  5. using Microsoft.AspNetCore.Builder;  
  6. using Microsoft.AspNetCore.Hosting;  
  7. using Microsoft.AspNetCore.Http;  
  8. using Microsoft.Extensions.DependencyInjection;  
  9. using Microsoft.Extensions.Logging;  
  10.    
  11. namespace AureliaHelloWorld  
  12. {  
  13.     public class Startup  
  14.     {  
  15.         // This method gets called by the runtime. Use this method to add services to the container.  
  16.         // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940  
  17.         public void ConfigureServices(IServiceCollection services)  
  18.         {  
  19.         }  
  20.    
  21.         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.  
  22.         public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)  
  23.         {  
  24.             loggerFactory.AddConsole();  
  25.    
  26.             if (env.IsDevelopment())  
  27.             {  
  28.                 app.UseDeveloperExceptionPage();  
  29.             }  
  30.    
  31.             app.UseFileServer();  
  32.    
  33.             app.Run(async (context) =>  
  34.             {  
  35.                 await context.Response.WriteAsync("Hello World!");  
  36.             });  
  37.         }  
  38.     }  
  39. }  
Possible Error
 
I think possibly we will get the given error below.
 
 
 
Therefore, we need to install aurelia-pal Browser in our project.
 
Command

"jspm install npm:aurelia-pal-browser" 
 
Output
 
Finally, we got it.
 

References 
Conclusion
 
We learned how to create an Aurelia single page application in ASP.NET Core 1.0 and I hope you liked this article. Please share your valuable suggestions and feedback.