Using WebApi 2? I think I got this. It drove me insane for long enough.
Okay, from the top. Create a new ASP.NET WebApi project.
Open the project folder (the one where the .csproj file is) in a command prompt.
Run jspm init. Accept all the defaults except for picking Typescript as your transpiler.
Run
jspm install aurelia-framework aurelia-bootstrapper aurelia-pal-browser
Make the first section of your config.js file look like this:
System.config({
baseURL: "/",
defaultJSExtensions: true,
transpiler: "typescript",
paths: {
"*": "client/*",
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
}
You can use src instead of client but I like client because there's a lot of source code elsewhere, if you understand me.
Okay, now we're getting somewhere. Pop open your Views folder, open up index.cshtml and make it look like this -
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Aurelia</title>
</head>
<body aurelia-app>
<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
Next, add a file called typings.json at the root of your project and chuck the following into it.
{
"name": "WhatEverYouCalledThisThing",
"dependencies": {
"aurelia-binding": "github:aurelia/binding",
"aurelia-bootstrapper": "github:aurelia/bootstrapper",
"aurelia-dependency-injection": "github:aurelia/dependency-injection",
"aurelia-event-aggregator": "github:aurelia/event-aggregator",
"aurelia-fetch-client": "github:aurelia/fetch-client",
"aurelia-framework": "github:aurelia/framework",
"aurelia-history": "github:aurelia/history",
"aurelia-history-browser": "github:aurelia/history-browser",
"aurelia-loader": "github:aurelia/loader",
"aurelia-logging": "github:aurelia/logging",
"aurelia-logging-console": "github:aurelia/logging-console",
"aurelia-metadata": "github:aurelia/metadata",
"aurelia-pal": "github:aurelia/pal",
"aurelia-pal-browser": "github:aurelia/pal-browser",
"aurelia-path": "github:aurelia/path",
"aurelia-polyfills": "github:aurelia/polyfills",
"aurelia-route-recognizer": "github:aurelia/route-recognizer",
"aurelia-router": "github:aurelia/router",
"aurelia-task-queue": "github:aurelia/task-queue",
"aurelia-templating": "github:aurelia/templating",
"aurelia-templating-binding": "github:aurelia/templating-binding",
"aurelia-templating-resources": "github:aurelia/templating-resources",
"aurelia-templating-router": "github:aurelia/templating-router"
},
"globalDevDependencies": {
"angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459",
"aurelia-protractor": "github:aurelia/typings/dist/aurelia-protractor.d.ts",
"jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
"selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654"
},
"globalDependencies": {
"url":
"github:aurelia/fetch-client/doc/url.d.ts#bbe0777ef710d889a05759a65fa2c9c3865fc618",
"whatwg-fetch": "registry:dt/whatwg-fetch#0.0.0+20160524142046"
}
}
then quickly run
npm install typings –g
or, if you hate waiting,
yarn global add typings
and then
typings install
Almost there, just two more steps.
First, create a file called typings.d.ts in the root of your src or client folder and add this line to it -
/// <reference path="../typings/index.d.ts" />
And finally, open up the nuget package manager console and hit it with
Install-Package es6-promise.TypeScript.DefinitelyTyped
and then
Install-Package es6-collections.TypeScript.DefinitelyTyped
And you should be all set.
This doesn't bundle things nicely for you and you're going to find that CSS is probably best added in the HEAD of your HTML - sorry! - but it's enough to get things working.
And for production, you don't really want WebApi hosting your SPA anyway.