Skip to content

Commit cb1270f

Browse files
committed
feat(mobile): add support for generating App Shell in index.html
1 parent f717bde commit cb1270f

File tree

8 files changed

+71
-9
lines changed

8 files changed

+71
-9
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {provide} from '@angular/core';
2+
import {APP_BASE_HREF} from '@angular/common';
3+
import {<%= jsComponentName %>AppComponent} from './app/';
4+
import {
5+
REQUEST_URL,
6+
ORIGIN_URL
7+
} from 'angular2-universal';
8+
9+
export const options = {
10+
directives: [
11+
// The component that will become the main App Shell
12+
<%= jsComponentName %>AppComponent
13+
],
14+
platformProviders: [
15+
provide(ORIGIN_URL, {
16+
useValue: ''
17+
})
18+
],
19+
providers: [
20+
// What URL should Angular be treating the app as if navigating
21+
provide(APP_BASE_HREF, {useValue: '/'}),
22+
provide(REQUEST_URL, {useValue: '/'})
23+
],
24+
async: true,
25+
preboot: false
26+
};
27+

addon/ng2/blueprints/ng2/files/__path__/app/__name__.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import { Component } from '@angular/core';
33
@Component({
44
moduleId: module.id,
55
selector: '<%= htmlComponentName %>-app',
6-
templateUrl: '<%= htmlComponentName %>.component.html',
7-
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']
6+
<% if (isMobile) { %>template: `
7+
<h1>
8+
{{title}}
9+
</h1>
10+
`,
11+
styles: []<% } else { %>templateUrl: '<%= htmlComponentName %>.component.html',
12+
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']<% } %>
813
})
914
export class <%= jsComponentName %>AppComponent {
1015
title = '<%= htmlComponentName %> works!';

addon/ng2/blueprints/ng2/files/__path__/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
},
1818

1919
"files": [
20-
"main.ts",
20+
"main.ts",<% if (isMobile) { %>
21+
"main-app-shell.ts",<% } %>
2122
"typings.d.ts"
2223
]
2324
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
/// <reference path="<%= refToTypings %>/typings/browser.d.ts" />
2-
3-
declare var module: { id: string };
2+
<% if(!isMobile) { %>declare var module: { id: string };<% } %>

addon/ng2/blueprints/ng2/files/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
"systemjs": "0.19.26",
2828
"zone.js": "^0.6.12"
2929
},
30-
"devDependencies": {
30+
"devDependencies": {<% if(isMobile) { %>
31+
"@angular/platform-server": "2.0.0-rc.1",
32+
"angular2-universal":"^0.100.3",
33+
"angular2-universal-polyfills": "^0.4.1",
34+
"preboot": "^2.0.10",<% } %>
3135
"angular-cli": "^<%= version %>",
3236
"clang-format": "^1.0.35",
3337
"codelyzer": "0.0.14",

addon/ng2/blueprints/ng2/files/typings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654"
66
},
77
"ambientDependencies": {
8-
"es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654"
8+
"es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654"<% if (isMobile) {%>,
9+
"node": "registry:dt/node#4.0.0+20160509154515" <% } %>
910
}
1011
}

lib/broccoli/angular2-app.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,20 @@ class Angular2App extends BroccoliPlugin {
139139

140140
var merged = new BroccoliMergeTrees(buildTrees, { overwrite: true });
141141

142+
if (this.ngConfig.apps[0].mobile) {
143+
let AppShellPlugin = require('angular2-broccoli-prerender').AppShellPlugin;
144+
merged = new BroccoliMergeTrees([merged, new AppShellPlugin(merged, 'index.html', 'main-app-shell')], {
145+
overwrite: true
146+
});
147+
}
148+
142149
if (loadEnvironment(this.project).production) {
143150
merged = this._getBundleTree(merged);
144151
}
145152

146153
return new BroccoliFunnel(merged, {
147-
destDir: this._destDir
154+
destDir: this._destDir,
155+
overwrite: true
148156
});
149157
}
150158

package.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
},
3131
"homepage": "https://github.com/angular/angular-cli",
3232
"dependencies": {
33+
"@angular/common": "2.0.0-rc.1",
34+
"@angular/compiler": "2.0.0-rc.1",
35+
"@angular/core": "2.0.0-rc.1",
36+
"@angular/platform-browser": "2.0.0-rc.1",
37+
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
38+
"@angular/platform-server": "2.0.0-rc.1",
39+
"@angular/router": "2.0.0-rc.1",
40+
"angular2-broccoli-prerender": "^0.11.0",
41+
"angular2-service-worker": "0.1.11",
42+
"angular2-universal": "^0.100.3",
43+
"angular2-universal-polyfills": "^0.4.1",
3344
"broccoli": "^1.0.0-beta.7",
3445
"broccoli-caching-writer": "^2.2.1",
3546
"broccoli-concat": "^2.2.0",
@@ -40,20 +51,26 @@
4051
"chalk": "^1.1.3",
4152
"ember-cli": "2.5.0",
4253
"ember-cli-string-utils": "^1.0.0",
54+
"es6-shim": "^0.35.0",
4355
"exit": "^0.1.2",
4456
"fs-extra": "^0.30.0",
4557
"glob": "^7.0.3",
4658
"handlebars": "^4.0.5",
4759
"leek": "0.0.21",
4860
"lodash": "^4.11.1",
4961
"opn": "4.0.1",
62+
"preboot": "^2.0.10",
63+
"reflect-metadata": "0.1.3",
5064
"resolve": "^1.1.7",
65+
"rxjs": "^5.0.0-beta.6",
5166
"shelljs": "^0.7.0",
5267
"silent-error": "^1.0.0",
5368
"symlink-or-copy": "^1.0.3",
69+
"systemjs": "0.19.26",
5470
"systemjs-builder": "^0.15.16",
5571
"typescript": "^1.8.10",
56-
"typings": "^0.8.1"
72+
"typings": "^0.8.1",
73+
"zone.js": "^0.6.12"
5774
},
5875
"ember-addon": {
5976
"paths": [

0 commit comments

Comments
 (0)