add aot (WIP)

This commit is contained in:
Filipe Silva 2016-11-14 17:07:39 +00:00
parent 0d74c9332f
commit b0c4422a97
9 changed files with 110 additions and 5 deletions

View File

@ -0,0 +1,3 @@
**/*.js
aot/**/*.ts
!rollup-config.js

View File

@ -0,0 +1,5 @@
{
"port": 8000,
"files": ["./aot/**/*.{html,htm,css,js}"],
"server": { "baseDir": "./aot" }
}

View File

@ -0,0 +1,36 @@
<!-- #docregion -->
<!DOCTYPE html>
<html>
<head>
<base href="/">
<title>Angular Tour of Heroes</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<script src="https://code.angularjs.org/1.5.5/angular.js"></script>
<script src="https://code.angularjs.org/1.5.5/angular-animate.js"></script>
<script src="https://code.angularjs.org/1.5.5/angular-resource.js"></script>
<script src="https://code.angularjs.org/1.5.5/angular-route.js"></script>
<script src="app.module.ng1.js"></script>
<script src="app.config.js"></script>
<script src="app.animations.js"></script>
<script src="core/core.module.js"></script>
<script src="core/phone/phone.module.js"></script>
<script src="phone-list/phone-list.module.js"></script>
<script src="phone-detail/phone-detail.module.js"></script>
<script src="shim.min.js"></script>
<script src="zone.min.js"></script>
<!-- #docregion moduleId -->
<script>window.module = 'aot';</script>
<!-- #enddocregion moduleId -->
</head>
<body>
<my-app>Loading...</my-app>
</body>
<script src="dist/build.js"></script>
</html>

View File

@ -59,7 +59,7 @@ import { PhoneDetailComponent } from './phone-detail/phone-detail.component';
// #enddocregion phone
{
provide: '$routeParams',
useFactory: (i: any) => i.get('$routeParams'),
useFactory: routeParamsFactory,
deps: ['$injector']
}
// #docregion phone
@ -73,3 +73,9 @@ export class AppModule {
// #docregion bare
}
// #enddocregion bare, upgrademodule, httpmodule, phone, phonelist, phonedetail, checkmarkpipe
// #docregion routeparams
export function routeParamsFactory(i: any) {
return i.get('$routeParams');
}
// #enddocregion routeparams

View File

@ -0,0 +1,11 @@
// #docregion bootstrap
import { platformBrowser } from '@angular/platform-browser';
import { UpgradeModule } from '@angular/upgrade/static';
import { AppModuleNgFactory } from '../aot/app/app.module.ngfactory';
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory).then(platformRef => {
let upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.documentElement, ['phonecatApp']);
});
// #enddocregion bootstrap

View File

@ -1,5 +1,4 @@
// #docregion bootstrap
declare var angular: angular.IAngularStatic;
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { UpgradeModule } from '@angular/upgrade/static';

View File

@ -23,9 +23,7 @@ export class PhoneDetailComponent {
phone: PhoneData;
mainImageUrl: string;
constructor(@Inject('$routeParams')
$routeParams: angular.route.IRouteParamsService,
phone: Phone) {
constructor(@Inject('$routeParams') $routeParams: any, phone: Phone) {
phone.get($routeParams['phoneId']).subscribe(phone => {
this.phone = phone;
this.setImage(phone.images[0]);

View File

@ -0,0 +1,21 @@
// #docregion
import rollup from 'rollup'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify'
//paths are relative to the execution path
export default {
entry: 'app/main-aot.js',
dest: 'aot/dist/build.js', // output a single application bundle
sourceMap: true,
sourceMapFile: 'aot/dist/build.js.map',
format: 'iife',
plugins: [
nodeResolve({jsnext: true, module: true}),
commonjs({
include: ['node_modules/rxjs/**']
}),
uglify()
]
}

View File

@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"typeRoots": [
"../../node_modules/@types/"
]
},
"files": [
"app/app.module.ts",
"app/main-aot.ts"
],
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit" : true
}
}