Skip to content

Commit 1b2b143

Browse files
arknottsAndrewPoyntz
authored andcommitted
AoT compilation updates (#4)
* AoT compilation updates Changes needed for AoT compilation. Mostly revolving around using ngc compiler rather than tsc. Also added a module at index.ts or the compiler would complain. * Add final else as catch-all If tsc is configured to use noImplicitReturns this will fail to compile. This should fix that while maintaining existing functionality. * Update travis config Uses new/renamed build npm script.
1 parent 68198ce commit 1b2b143

File tree

7 files changed

+24
-4
lines changed

7 files changed

+24
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ node_modules
55
**/*.d.ts
66
**/*.js
77
**/*.js.map
8+
/compiled
9+
*.metadata.json

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ node_modules
55
.travis.yml
66
tsconfig.json
77
.idea
8-
**/*.iml
8+
**/*.iml
9+
/compiled

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ node_js:
55

66
install:
77
- npm install
8-
- npm run tsc
8+
- npm run build

index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NgModule } from '@angular/core';
2+
import { TimeAgoPipe } from './time-ago-pipe';
3+
4+
@NgModule({
5+
declarations: [TimeAgoPipe],
6+
exports: [TimeAgoPipe],
7+
})
8+
export class TimeAgoPipeModule { }
9+
10+
export * from './time-ago-pipe';

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "time-ago-pipe.js",
66
"typings": "time-ago-pipe.d.ts",
77
"scripts": {
8-
"tsc": "tsc",
8+
"build": "ngc",
99
"test": "mocha --reporter spec"
1010
},
1111
"repository": {
@@ -27,7 +27,10 @@
2727
"node": ">=4.2.4"
2828
},
2929
"devDependencies": {
30+
"@angular/compiler": "^2.4.5",
31+
"@angular/compiler-cli": "^2.4.5",
3032
"@angular/core": "^2.0.1",
33+
"@angular/platform-server": "^2.4.5",
3134
"@types/core-js": "^0.9.34",
3235
"@types/mocha": "^2.2.32",
3336
"@types/node": "^6.0.41",

time-ago-pipe.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class TimeAgoPipe implements PipeTransform, OnDestroy {
1818
this.ngZone.run(() => this.changeDetectorRef.markForCheck());
1919
}, timeToUpdate);
2020
}
21+
return null;
2122
});
2223
let minutes = Math.round(Math.abs(seconds / 60));
2324
let hours = Math.round(Math.abs(minutes / 60));
@@ -44,7 +45,7 @@ export class TimeAgoPipe implements PipeTransform, OnDestroy {
4445
return months + ' months ago';
4546
} else if (days <= 545) {
4647
return 'a year ago';
47-
} else if (days > 546) {
48+
} else { // (days > 545)
4849
return years + ' years ago';
4950
}
5051
}

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"removeComments": false,
1111
"noImplicitAny": false
1212
},
13+
"angularCompilerOptions": {
14+
"genDir": "compiled"
15+
},
1316
"types":[
1417
"core-js",
1518
"node"

0 commit comments

Comments
 (0)