-
Notifications
You must be signed in to change notification settings - Fork 517
Update Angular2Spa template to Angular 2.0/TypeScript 2.0, based on @MarkPieszak's PR #321
Conversation
…reference (no longer needed).
why is @types/node not added to devDependencies with other @types ? |
@MarkPieszak, do you have any feedback on the simplifications/changes I've made here? Your PR was extremely helpful. On top of that, the main things I wanted to change were:
I also attempted to get the Angular 2 compiler ( @hheexx - check the later commits. It's in |
}); | ||
|
||
return requestZone.run<Promise<string>>(() => platform.serializeModule(AppModule)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner I like it 👍
HomeComponent | ||
], | ||
imports: [ | ||
UniversalModule, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave a Note that UniversalModule
should be the first Import? (Just want to prevent common errors that can creep up from this)
Also, we should point out that BrowserModule
HttpModule
JsonpModule
are all automatically included here.
(The same goes for the Node versions on the main.server.ts side, NodeModule / NodeHttpModule etc)
Things can error out if they include those. We're working on looking into fixing that.
Patrick also thought it'd be nice to keep the main files separate since that allows someone to have specific platform logic injected for either browser/server, but it's up to you. It's definitely cleaner/simpler this way!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep server and client main files separate.
For me they diverged very early in development. And I am pretty sure it will for most users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the comment about UniversalModule
(and BrowserModule/HttpModule/JsonpModule)
main files separate
I'd hope that the boot files serve that purpose well enough (this is where you configure DI, after all), and am reluctant to add more duplicate files. Having one root @NgModule
makes things much clearer, especially given how much tedious config goes into that file. We can monitor this and see if people often report issues that are best solved by having separate root modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have logic in main file based on platform? Then we don't need 2 files.
if (server) {
declarations: [......]
} else if (client) {
declarations: [.....]
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hheexx Yes, just import { isNode, isBrowser } from 'angular2-universal';
and then do if (isNode) { ... }
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is sweet. I would add it as a comment so people know.
Oh.. I see they are removed in later commit. |
const _config = Object.assign({ | ||
get cancel() { return cancel; }, | ||
cancelHandler() { return Zone.current.get('cancel') } | ||
}, platformConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only thing I'm worried about is the Zone canceling itself if errors/issues occur.
Hence these cancelHandler's being added to the zone.
Let me look into it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, please let me know if you think something needs to be added for this.
|
||
// * NOTE: Needs to be your first import (!) | ||
UniversalModule, | ||
// * ^ BrowserModule, HttpModule, and JsonpModule are included here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These notes would be nice to keep to avoid issues if people think they need to add them in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@SteveSandersonMS One thing recommended by the Angular team is DOMContentLoaded. You don't want angular bootstrapping prior to that, it can cause sporadic/bizarre issues. Can we leave that in there?
Another thing I thought might be beneficial is leaving those comments about UniversalModule. It DepInjects several modules (for you), and if they're included on top of it, it can error things out. (We're looking into it fixing this or at least providing better error messaging for it) As for AOT Compilation, right now we don't have it fully working, it would be additional code needed in the boot-server, but there's more that needs to be done to get that working on our end.
Webpack2 does work with Universal, what problems were you getting with it, we can look into it another time. |
…t all. Is used by other templates though.
Thanks for the feedback. Done.
The issue isn't just making it work at runtime in Univeral. Right now I'm not successful in being able to actually do the AOT compilation at all, because it's not generally compatible with arbitrary webpack configs (e.g., using
No, that part works fine. I was meaning to say that the end-to-end story with Webpack 2 tree shaking isn't usable right now because of the inability to precompile Angular 2 templates. |
Thanks for the feedback! This is now merged into the default branch. I'll publish actual Yeoman templates tomorrow. |
Excellent! :) Cheers. |
Following on from @MarkPieszak's PR #319, I've simplified the template further as far as I think makes sense at the moment.
Putting this out as a PR for feedback before merging and publishing.