Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Add AureliaSpa template #398

Closed
wants to merge 12 commits into from
Closed

Add AureliaSpa template #398

wants to merge 12 commits into from

Conversation

kmkatsma
Copy link
Contributor

This PR adds a new AureliaSpa folder to the existing templates folder.

Made attempts to be as consistent as possible with existing templates, but this does follow different webpack template build process - it uses a single webpack config utilizing the AureliaWebpackPlugin. However, I tried to keep the WebPack configuration consistent with the configurations that exist in official Aurelia webpack skeletons, except EasyWebpack has been removed for closer match to the existing webpack templates in this repo.

Other things of note with regard to comparison with other templates:

  1. The nav css had to be modified to deal with the default class added by aurelia to elements (perhaps there is another way).
  2. The menu is build dynamically, instead of statically
  3. Single boot file, given no server side rendering
  4. The fetchdata.ts has some typings overrides added specifically to deal with some current issues in "official" typings files

@SteveSandersonMS, @MarkPieszak, @EisenbergEffect

acu-kkatsma and others added 6 commits October 18, 2016 12:06
Added @typings/node to package.json, removed direct typings reference
Small webpack.config.js and tsconfig.json changes for similarity to Angular2 version
@dnfclas
Copy link

dnfclas commented Oct 22, 2016

Hi @kmkatsma, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla2.dotnetfoundation.org.

TTYL, DNFBOT;

@dnfclas
Copy link

dnfclas commented Oct 22, 2016

@kmkatsma, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, DNFBOT;

@SteveSandersonMS
Copy link
Member

Thanks @kmkatsma! Overall this looks great. You're identified most of the limitations yourself above, and I appreciate that they are beyond your control. Thanks for making it consistent with the other templates where possible.

I'll now review and comment on the actual code. Since I don't know Aurelia, I'll wait for @EisenbergEffect to comment on whether Aurelia is being used optimally. Mostly I'll be limited to commenting on the cosmetic aspects of the code - hope you don't mind my rather trivial comments!

<div class='clearfix'></div>
<div class='navbar-collapse collapse'>
<ul class='nav navbar-nav'>
<li class="${row.isActive ? 'link-active' : ''}" repeat.for = "row of router.navigation" >

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, I would put the repeat.for first on the li, before the class binding.

@EisenbergEffect
Copy link

I left one minor style comment related to the Aurelia code. Everything else looks fine to me :)

@MarkPieszak
Copy link
Contributor

Forgot to say, great job @kmkatsma ! 💯 👍

@EisenbergEffect
Copy link

Agree with @MarkPieszak This is a really awesome contribution. When it this goes live, if you would like to @kmkatsma we can feature you on our official blog for this work. I'm sure a lot of people will be interested.

Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kmkatsma Thanks again for this excellent contribution! I hope you don't mind these comments - most of them are pretty trivial.

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>33d8dad9-74f9-471d-8bad-55f828faa736</ProjectGuid>
<RootNamespace>Angular2</RootNamespace>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this

@@ -0,0 +1,14 @@
<template>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent quote style in this file. In TypeScript let's use single-quotes. In HTML templates, I don't know if Aurelia community has a standard, but can you find out what it is and use that?

Copy link

@EisenbergEffect EisenbergEffect Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer single quotes in JS/TS and double quotes in HTML.

</div>
</div>
</div>
</template>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing trailing linebreak which is present in most files. Could you add one here and to any other TS/JS/HTML/CSS file where it's missing?

@@ -0,0 +1,19 @@
import {Aurelia} from 'aurelia-framework';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some few formatting issues in this file:

  • missing spaces around { ImportedModule }
  • The config.map object looks pretty strange. Not sure if you were trying to line things up with tabs or something, but it's not lined up now. Also some of the key-value pairs have spaces after the colon and others don't. Could you lay this code out more conventionally?

}
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 18 seems like unnecessary whitespace, then there's a missing trailing linebreak.

entry: {
'app': [], // <-- this array will be filled by the aurelia-webpack-plugin
'aurelia-bootstrap': aureliaBootstrap,
'aurelia-modules': aureliaModules.filter(pkg => aureliaBootstrap.indexOf(pkg) === -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these dependencies going into a separate bundle? Couldn't they just be included in aurelia-bootstrap? (which they would be by default if this line wasn't here)

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this file is needed. It's not present in any of the other templates.

},
plugins: [
new webpack.ProvidePlugin({
regeneratorRuntime: 'regenerator-runtime', // to support await/async syntax
Copy link
Member

@SteveSandersonMS SteveSandersonMS Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that needed? I didn't see any await/async anywhere. Can this be simplified?

Promise: 'bluebird', // because Edge browser has slow native Promise object
$: 'jquery', // because 'bootstrap' by Twitter depends on this
jQuery: 'jquery', // just an alias
'window.jQuery': 'jquery' // this doesn't expose jQuery property for window, but exposes it to every module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all three of these aliases for jQuery?

{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
HotModuleReplacement = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we'll get away with just setting this to false. The problem is, people will change it to true, and then you get a really weird and non-descriptive error that people will regard as a bug. It's reasonable for people to think that if some option exists that you should be able to use it.

Obviously the ideal solution would be if HMR could be made to work. I'd hope that's not impossible, since it's quite trivial to enable with Angular/Knockout/React, but I don't know if Aurelia does something that can't handle it.

If it's not possible to make work, can you somehow stop the unrelated-seeming error message, and replace it with something like "Sorry, Hot Module Replacement is not supported with Aurelia"?

@kmkatsma
Copy link
Contributor Author

@SteveSandersonMS - thanks - a lot of good comments here, responded to couple, but too many to address individually. =) I will look at them all. I was trying to clean things up for consistency, and this helps a ton.

@MarkPieszak @EisenbergEffect - thanks, appreciate it! I would definitely be good with a feature on the Aurelia blog! These kinds of projects are really important - anything we can do to help developers get a foothold into technologies like these is worthwhile. And I think Aurelia deserved a place here as well. =)

@EisenbergEffect
Copy link

I think doing this sort of thing in a constructor is bad, yes. I wouldn't
recommend that in any language. Constructor code should always by
synchronous.

On Mon, Oct 24, 2016 at 6:54 AM, Steve Sanderson notifications@github.com
wrote:

@SteveSandersonMS commented on this pull request.

In templates/AureliaSpa/ClientApp/app/components/fetchdata/fetchdata.ts
#398:

@@ -0,0 +1,27 @@
+///
+///
+import {HttpClient} from 'aurelia-fetch-client';
+import {inject} from 'aurelia-framework';
+
+@Inject(HttpClient)
+export class Fetchdata {

  • public forecasts: WeatherForecast[];
  • http: HttpClient;

@EisenbergEffect https://github.com/EisenbergEffect It's the
simplicity/extensibility tradeoff. In the Angular/Knockout/React templates
we've followed this exact approach, as we're trying to make the templates
accessible to newcompers and limit the concept count. People who get into
using one of those frameworks won't struggle to create a service layer. In
the ReactRedux template, we do the whole Redux thing which is a whole extra
level of sophistication, but that's just fundamental to doing Redux. I
think for this Aurelia template it's a reasonable choice of simplicity vs
extensibility already, but we could change it if you think it's just flat
out bad.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#398, or mute the
thread
https://github.com/notifications/unsubscribe-auth/AAIBnccSp7t35BhGwypRsjQjHbEvaTTAks5q3LiwgaJpZM4Kd5Pj
.

Rob Eisenberg,
President - Blue Spire
aurelia.io

@SteveSandersonMS
Copy link
Member

@EisenbergEffect It's a reasonable point but perhaps we're getting a bit side-tracked.

@kmkatsma's Thanks - awaiting your updates :)

@kmkatsma
Copy link
Contributor Author

Have pushed in update in updates for all the review items. There's two things to note regarding resolutions (or somewhat lack thereof ).

  1. For fetchdata, I couldn't eliminate need for the d.ts custom entries using the new types approach. I could move to a typings folder, but I think that is not any better. I also left the api call in constructor for now since it's same as Angular2 template, but would be willing to refactor this.
  2. For dotnet publish, it builds, and I have its output definition matching angular2 template, but I am having issues getting the publish of either Angular2 or Aurelia running in IIS on my dev VM (built off the new windows 10 pro dev images). I spent a fair amount of time on this, working through some stackoverflow answers to no avail. I can spend some more time if we want to get a running confirmation before merging.
  3. HMR - I was able to get app to run with this setting enabled using a hack to webpack config, but it caused issues when running in asp env production mode. So at this point, I put a comment in Startup.cs to the effect that HMR has issues, and to leave the setting false. Definitely this is something that is high priority for developer experience, but the webpack integration with Aurelia is still work in progress. I think the convention based approach (which is advantage from code perspective) actually makes it hard for WebPack to find all its pieces, and so are dependent on the custom plugin to pull in all the pieces and run it.

Let me know thoughts on these things - have learned a ton here going through this! I think the back end integration of these templates is a huge win, and removes a lot of friction we've seen since everything moved to client in a SPA. I can definitely see people wanting to get more things into them. =)

@kmkatsma
Copy link
Contributor Author

Added a commit that fixed issues with dotnet publish.

First, when publishing to virtual directory that is not at root, the router was having issues due to base url set to "" in the layout.cshtml. Apparently this works for angular2 in publish mode, but causes issues for aurelia routing. I removed this, and now works in dev and publish mode under IIS virtual directory.

Second change was to remove node_modules from the items included in publish process. It made the publish really big and run really slow, and is not needed since webpack runs as pre-publish step.

There's a funky bug in publish process where the generated web.config keeps appending extra arguments on each run if you don't delete the web.config first. This was causing my publish problems.

Copy link

@niieani niieani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments regarding the Webpack config.

"jquery": "^2.2.1"
},
"devDependencies": {
"@types/node": "^6.0.45",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the node types used for?

resolve: { extensions: [ '.js', '.ts' ] },
devtool: isDevBuild ? 'inline-source-map' : null,
entry: {
'app': [], // <-- this array will be filled by the aurelia-webpack-plugin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest Webpack@beta currently errors when an array is empty (it's an ongoing bug). I might be better to instead point it to where the main.js file is, as that should be in the context anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changed in the current version too, so I think we're OK.

var outDir = path.resolve('./wwwroot/dist');
var baseUrl = '/';
var project = require('./package.json');
var aureliaModules = Object.keys(project.dependencies).filter(dep => dep.startsWith('aurelia-'));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only gets the list of first-level dependencies of Aurelia, which means not all of Aurelia's dependencies might get into the aurelia-modules bundle specified in the entry config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. However this approach is no longer used in the current version anyway - dependencies are now listed explicitly.

SteveSandersonMS pushed a commit that referenced this pull request Oct 28, 2016
@SteveSandersonMS
Copy link
Member

Thanks again @kmkatsma - this is now merged :) Also I've published generator-aspnetcore-spa version 0.4.0 in which you'll find the new "Aurelia" option.

I made a few further tweaks - hope you don't mind:

  • Switched to use the same 'vendor' bundle pattern as the other templates
  • Switched to use external source maps configured for VS/VSCode compatibility (again, to match the other templates)
  • Changed the "log or not" choice to depend on which webpack build configuration you used, rather than based on whether you have localhost in your hostname
  • Minor stylistic tweaks

@MarkPieszak
Copy link
Contributor

MarkPieszak commented Oct 28, 2016

@niieani The @types/Node is mainly to make Visual Studio happy when it comes to require and other similar things.

Also great! Can't wait to take it for a test drive 💯

@EisenbergEffect
Copy link

Awesome! @kmkatsma We'd love to have you featured on the official Aurelia blog talking about this new options for our customers :) Please email me and let's make some plans. Thanks for the great work!

@mttmccb mttmccb mentioned this pull request Oct 28, 2016
@ClaudioNunes
Copy link

The only thing missing is HMR. Maybe @niieani could help with this.

@niieani
Copy link

niieani commented Oct 28, 2016

HMR support is planned. Once major Aurelia+Webpack fixes land in November, I might tackle basic HMR in December. We'll see how difficult it will be.

@kmkatsma
Copy link
Contributor Author

@SteveSandersonMS - your changes wrapped this up nicely, I think!

@ClaudioNunes
Copy link

@niieani any news about HMR support?

@niieani
Copy link

niieani commented Nov 15, 2016

@ClaudioNunes not yet. But work is on-going. See aurelia/skeleton-navigation#714 for a couple of updates (HMR for CSS works).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants