From 4718ca2bd4879d72141872cf436b6761095b5891 Mon Sep 17 00:00:00 2001 From: Chris Howe Date: Sun, 5 Feb 2017 18:30:07 -0600 Subject: [PATCH 1/2] merge browser and node default modules to maintain common NgModule parts --- .../files/__path__/app/app.browser.module.ts | 39 --------------- .../app/{app.node.module.ts => app.module.ts} | 48 +++++++++++++++---- .../universal/files/__path__/client.ts | 2 +- .../universal/files/__path__/server.ts | 4 +- 4 files changed, 43 insertions(+), 50 deletions(-) delete mode 100644 packages/universal-cli/blueprints/universal/files/__path__/app/app.browser.module.ts rename packages/universal-cli/blueprints/universal/files/__path__/app/{app.node.module.ts => app.module.ts} (50%) diff --git a/packages/universal-cli/blueprints/universal/files/__path__/app/app.browser.module.ts b/packages/universal-cli/blueprints/universal/files/__path__/app/app.browser.module.ts deleted file mode 100644 index 70d9d9525f80..000000000000 --- a/packages/universal-cli/blueprints/universal/files/__path__/app/app.browser.module.ts +++ /dev/null @@ -1,39 +0,0 @@ -/** - * This file and `main.node.ts` are identical, at the moment(!) - * By splitting these, you're able to create logic, imports, etc that are "Platform" specific. - * If you want your code to be completely Universal and don't need that - * You can also just have 1 file, that is imported into both - * client.ts and server.ts - */ - -import { NgModule } from '@angular/core'; -import { UniversalModule } from 'angular2-universal'; -import { FormsModule } from '@angular/forms'; -import { AppComponent } from './index'; -// import { RouterModule } from '@angular/router'; -// import { appRoutes } from './app/app.routing'; - -/** - * Top-level NgModule "container" - */ -@NgModule({ - /** Root App Component */ - bootstrap: [ AppComponent ], - /** Our Components */ - declarations: [ AppComponent ], - imports: [ - /** - * NOTE: Needs to be your first import (!) - * BrowserModule, HttpModule, and JsonpModule are included - */ - UniversalModule, - FormsModule - /** - * using routes - */ - // RouterModule.forRoot(appRoutes) - ] -}) -export class AppModule { - -} diff --git a/packages/universal-cli/blueprints/universal/files/__path__/app/app.node.module.ts b/packages/universal-cli/blueprints/universal/files/__path__/app/app.module.ts similarity index 50% rename from packages/universal-cli/blueprints/universal/files/__path__/app/app.node.module.ts rename to packages/universal-cli/blueprints/universal/files/__path__/app/app.module.ts index 89298579c259..c2539f9917d1 100644 --- a/packages/universal-cli/blueprints/universal/files/__path__/app/app.node.module.ts +++ b/packages/universal-cli/blueprints/universal/files/__path__/app/app.module.ts @@ -13,27 +13,59 @@ import { AppComponent } from './index'; // import { RouterModule } from '@angular/router'; // import { appRoutes } from './app/app.routing'; -/** - * Top-level NgModule "container" - */ -@NgModule({ +const commonModule = { /** Root App Component */ - bootstrap: [ AppComponent ], + bootstrap: [AppComponent], /** Our Components */ - declarations: [ AppComponent ], + declarations: [AppComponent], imports: [ /** * NOTE: Needs to be your first import (!) * NodeModule, NodeHttpModule, NodeJsonpModule are included */ UniversalModule, - FormsModule + FormsModule, /** * using routes */ // RouterModule.forRoot(appRoutes) - ] + ], + providers: [] +}; + +const uniqueToClientModule = { + bootstrap: [], + declarations: [], + imports: [], + providers: [] +}; + +const uniqueToServerModule = { + bootstrap: [], + declarations: [], + imports: [], + providers: [] +}; + +/** + * Top-level NgModule "container" + */ +@NgModule({ + bootstrap: [...commonModule.bootstrap, uniqueToClientModule.bootstrap], + declarations: [...commonModule.declarations, uniqueToClientModule.declarations], + imports: [...commonModule.imports, uniqueToClientModule.imports], + providers: [...commonModule.providers, uniqueToClientModule.providers] }) export class AppModule { } + +@NgModule({ + bootstrap: [...commonModule.bootstrap, uniqueToServerModule.bootstrap], + declarations: [...commonModule.declarations, uniqueToServerModule.declarations], + imports: [...commonModule.imports, uniqueToServerModule.imports], + providers: [...commonModule.providers, uniqueToServerModule.providers] +}) +export class AppNodeModule { + +} diff --git a/packages/universal-cli/blueprints/universal/files/__path__/client.ts b/packages/universal-cli/blueprints/universal/files/__path__/client.ts index 6e1dff147e6b..1fb2ca052273 100644 --- a/packages/universal-cli/blueprints/universal/files/__path__/client.ts +++ b/packages/universal-cli/blueprints/universal/files/__path__/client.ts @@ -6,7 +6,7 @@ import './__2.1.1.workaround.ts'; // temporary until 2.1.1 things are patched in import { enableProdMode } from '@angular/core'; import { environment } from './environments/environment'; import { platformUniversalDynamic } from 'angular2-universal'; -import { AppModule } from './app/app.browser.module'; +import { AppModule } from './app/app.module'; /** * enable prod mode for production environments diff --git a/packages/universal-cli/blueprints/universal/files/__path__/server.ts b/packages/universal-cli/blueprints/universal/files/__path__/server.ts index d9cd7b7067c3..52ad8cd458ee 100644 --- a/packages/universal-cli/blueprints/universal/files/__path__/server.ts +++ b/packages/universal-cli/blueprints/universal/files/__path__/server.ts @@ -8,7 +8,7 @@ import * as express from 'express'; import * as compression from 'compression'; import { createEngine } from 'angular2-express-engine'; import { enableProdMode } from '@angular/core'; -import { AppModule } from './app/app.node.module'; +import { AppNodeModule } from './app/app.module'; import { environment } from './environments/environment'; import { routes } from './server.routes'; @@ -56,7 +56,7 @@ function ngApp(req: any, res: any) { res.render('index', { req, res, - ngModule: AppModule, + ngModule: AppNodeModule, preboot: false, baseUrl: '/', requestUrl: req.originalUrl, From 238419be2bafd2be2358fc788affb46710aba9b5 Mon Sep 17 00:00:00 2001 From: Chris Howe Date: Sun, 5 Feb 2017 18:33:29 -0600 Subject: [PATCH 2/2] merge browser and node default modules to maintain common NgModule parts --- .../blueprints/universal/files/__path__/app/app.module.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/universal-cli/blueprints/universal/files/__path__/app/app.module.ts b/packages/universal-cli/blueprints/universal/files/__path__/app/app.module.ts index c2539f9917d1..6963a550b575 100644 --- a/packages/universal-cli/blueprints/universal/files/__path__/app/app.module.ts +++ b/packages/universal-cli/blueprints/universal/files/__path__/app/app.module.ts @@ -1,9 +1,11 @@ /** * This file and `main.browser.ts` are identical, at the moment(!) - * By splitting these, you're able to create logic, imports, etc that are "Platform" specific. + * By modifying the uniqueTo* definitions, you're able to create logic, + * imports, etc that are "Platform" specific. + * * If you want your code to be completely Universal and don't need that - * You can also just have 1 file, that is imported into both - * client.ts and server.ts + * You can also modiy just the commonModule definition + * */ import { NgModule } from '@angular/core';