From 8cb5c9304153fcde88b280df53920eb270a527d8 Mon Sep 17 00:00:00 2001 From: Liu Tim Date: Wed, 28 Dec 2016 22:20:31 +0800 Subject: [PATCH 1/4] feature(ng new): adds hmr to default start-up blueprint --- .../environments/environment.dev-hmr.ts | 4 +++ .../__path__/environments/environment.prod.ts | 3 +- .../__path__/environments/environment.ts | 3 +- .../blueprints/ng2/files/__path__/hmr.ts | 15 ++++++++++ .../blueprints/ng2/files/__path__/main.ts | 29 ++++++++++++++++++- .../blueprints/ng2/files/angular-cli.json | 1 + .../blueprints/ng2/files/package.json | 4 ++- 7 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.dev-hmr.ts create mode 100644 packages/angular-cli/blueprints/ng2/files/__path__/hmr.ts diff --git a/packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.dev-hmr.ts b/packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.dev-hmr.ts new file mode 100644 index 000000000000..396ec29aa9e5 --- /dev/null +++ b/packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.dev-hmr.ts @@ -0,0 +1,4 @@ +export const environment = { + production: false, + hmr: true +}; \ No newline at end of file diff --git a/packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.prod.ts b/packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.prod.ts index 3612073bc31c..0d7b86c805e9 100644 --- a/packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.prod.ts +++ b/packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.prod.ts @@ -1,3 +1,4 @@ export const environment = { - production: true + production: true, + hmr: false }; diff --git a/packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.ts b/packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.ts index 00313f16648e..db0b68cc2a48 100644 --- a/packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.ts +++ b/packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.ts @@ -4,5 +4,6 @@ // The list of which env maps to which file can be found in `angular-cli.json`. export const environment = { - production: false + production: false, + hmr: false }; diff --git a/packages/angular-cli/blueprints/ng2/files/__path__/hmr.ts b/packages/angular-cli/blueprints/ng2/files/__path__/hmr.ts new file mode 100644 index 000000000000..cdb4c2918f50 --- /dev/null +++ b/packages/angular-cli/blueprints/ng2/files/__path__/hmr.ts @@ -0,0 +1,15 @@ +import { NgModuleRef, ApplicationRef } from '@angular/core'; +import { createNewHosts } from '@angularclass/hmr'; + +export const hmrBootstrap = (module: any, bootstrap: () => Promise>) => { + let ngModule: NgModuleRef; + module.hot.accept(); + bootstrap().then(mod => ngModule = mod); + module.hot.dispose(() => { + let appRef: ApplicationRef = ngModule.injector.get(ApplicationRef); + let elements = appRef.components.map(c => c.location.nativeElement); + let makeVisible = createNewHosts(elements); + ngModule.destroy(); + makeVisible(); + }); +}; \ No newline at end of file diff --git a/packages/angular-cli/blueprints/ng2/files/__path__/main.ts b/packages/angular-cli/blueprints/ng2/files/__path__/main.ts index ac78a713c2d1..2c12d7b0eb11 100644 --- a/packages/angular-cli/blueprints/ng2/files/__path__/main.ts +++ b/packages/angular-cli/blueprints/ng2/files/__path__/main.ts @@ -1,12 +1,39 @@ +// import './polyfills.ts'; + +// import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; +// import { enableProdMode } from '@angular/core'; +// import { environment } from './environments/environment'; +// import { AppModule } from './app/app.module'; + +// if (environment.production) { +// enableProdMode(); +// } + +// platformBrowserDynamic().bootstrapModule(AppModule); + import './polyfills.ts'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; import { environment } from './environments/environment'; import { AppModule } from './app/app.module'; +import { hmrBootstrap } from './hmr'; if (environment.production) { enableProdMode(); } -platformBrowserDynamic().bootstrapModule(AppModule); +const bootstrap = () => { + return platformBrowserDynamic().bootstrapModule(AppModule); +}; + +if (environment.hmr) { + if (module['hot']) { + hmrBootstrap(module, bootstrap); + } else { + console.error('HMR is not enabled for webpack-dev-server!'); + console.info('Are you using the --hmr flag for ng serve?'); + } +} else { + bootstrap(); +} diff --git a/packages/angular-cli/blueprints/ng2/files/angular-cli.json b/packages/angular-cli/blueprints/ng2/files/angular-cli.json index 4fd88b98c1cf..12085f9c15c9 100644 --- a/packages/angular-cli/blueprints/ng2/files/angular-cli.json +++ b/packages/angular-cli/blueprints/ng2/files/angular-cli.json @@ -24,6 +24,7 @@ "environments": { "source": "environments/environment.ts", "dev": "environments/environment.ts", + "dev-hmr": "environments/environment.dev-hmr.ts", "prod": "environments/environment.prod.ts" } } diff --git a/packages/angular-cli/blueprints/ng2/files/package.json b/packages/angular-cli/blueprints/ng2/files/package.json index 28de1005ae14..541bc73bfd29 100644 --- a/packages/angular-cli/blueprints/ng2/files/package.json +++ b/packages/angular-cli/blueprints/ng2/files/package.json @@ -9,7 +9,8 @@ "lint": "tslint \"<%= sourceDir %>/**/*.ts\"", "test": "ng test", "pree2e": "webdriver-manager update --standalone false --gecko false", - "e2e": "protractor" + "e2e": "protractor", + "dev:hmr": "ng serve --hmr -e=dev-hmr" }, "private": true, "dependencies": { @@ -28,6 +29,7 @@ }, "devDependencies": { "@angular/compiler-cli": "^2.3.1", + "@angularclass/hmr": "^1.2.2", "@types/jasmine": "2.5.38", "@types/node": "^6.0.42", "angular-cli": "<%= version %>", From 269a8b251b3bf883295e9f0aa181939ae8283876 Mon Sep 17 00:00:00 2001 From: Liu Tim Date: Fri, 13 Jan 2017 19:45:41 +0800 Subject: [PATCH 2/4] enable aot and vendorChunk for gh:deploy --- .gitignore | 2 ++ packages/angular-cli/commands/github-pages-deploy.run.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index e4fc30216708..3cd3bf3255ed 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ tmp/ # Mac OSX Finder files. **/.DS_Store .DS_Store + +debug.log diff --git a/packages/angular-cli/commands/github-pages-deploy.run.ts b/packages/angular-cli/commands/github-pages-deploy.run.ts index 305e473e02dd..6f48cfea56dd 100644 --- a/packages/angular-cli/commands/github-pages-deploy.run.ts +++ b/packages/angular-cli/commands/github-pages-deploy.run.ts @@ -64,6 +64,8 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions, environment: options.environment, outputPath: outDir, baseHref: baseHref, + aot: true, + vendorChunk: true }; const createGithubRepoTask = new CreateGithubRepo({ From b1155edc2a246baf788124a03bec16945a860fea Mon Sep 17 00:00:00 2001 From: Liu Tim Date: Fri, 13 Jan 2017 19:58:53 +0800 Subject: [PATCH 3/4] enables aot and vendorChunk for gh:deploy --- packages/angular-cli/commands/github-pages-deploy.run.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/angular-cli/commands/github-pages-deploy.run.ts b/packages/angular-cli/commands/github-pages-deploy.run.ts index 6f48cfea56dd..811e4f816053 100644 --- a/packages/angular-cli/commands/github-pages-deploy.run.ts +++ b/packages/angular-cli/commands/github-pages-deploy.run.ts @@ -65,7 +65,7 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions, outputPath: outDir, baseHref: baseHref, aot: true, - vendorChunk: true + vendorChunk: true }; const createGithubRepoTask = new CreateGithubRepo({ From 6e925c8dc86b1b194810b140d14be0808e4c12d5 Mon Sep 17 00:00:00 2001 From: Liu Tim Date: Mon, 16 Jan 2017 19:29:35 +0800 Subject: [PATCH 4/4] removes unecessary space; attention: zone.js@0.7.5 cause problems, downgrade to 0.7.4 manually --- packages/angular-cli/commands/github-pages-deploy.run.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/angular-cli/commands/github-pages-deploy.run.ts b/packages/angular-cli/commands/github-pages-deploy.run.ts index 811e4f816053..6f48cfea56dd 100644 --- a/packages/angular-cli/commands/github-pages-deploy.run.ts +++ b/packages/angular-cli/commands/github-pages-deploy.run.ts @@ -65,7 +65,7 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions, outputPath: outDir, baseHref: baseHref, aot: true, - vendorChunk: true + vendorChunk: true }; const createGithubRepoTask = new CreateGithubRepo({