Skip to content

Commit 94e07b6

Browse files
author
sternbach
committed
fix(build): put out routing in a separate module and fix build
1 parent c35b202 commit 94e07b6

File tree

3 files changed

+50
-34
lines changed

3 files changed

+50
-34
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularjs-typescript-webpack",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "Angularjs-typescript-webpack starter project",
55
"repository": "https://github.com/vsternbach/angularjs-typescript-webpack",
66
"license": "MIT",
@@ -52,8 +52,10 @@
5252
"eventemitter3": "3.0.1"
5353
},
5454
"scripts": {
55-
"start": "copyfiles -f src/assets/* dist/ & webpack-dev-server --mode=development --open",
56-
"build": "rimraf dist & webpack --mode=production --optimize-minimize",
55+
"prestart": "rimraf dist & copyfiles -f src/assets/* dist/",
56+
"start": "webpack-dev-server --mode=development --open",
57+
"prebuild": "npm run prestart",
58+
"build": "webpack --mode=production --optimize-minimize",
5759
"test": "karma start --single-run",
5860
"test:dev": "karma start --browsers Chrome",
5961
"clean-build": "rimraf dist & copyfiles -f src/index.html dist/ & copyfiles -f src/assets/* dist/assets & npm run webpack-prod"

src/app/app-routing.module.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { StateProvider } from '@uirouter/angularjs';
2+
import { Ng1StateDeclaration } from '@uirouter/angularjs/lib/interface';
3+
import { getTypeName, NgModule } from 'angular-ts-decorators';
4+
import { DashboardComponent } from './dashboard/dashboard.component';
5+
import { HeroDetailComponent } from './hero-detail/hero-detail.component';
6+
import { HeroesComponent } from './heroes/heroes.component';
7+
8+
export interface UiState extends Ng1StateDeclaration {
9+
component?: any;
10+
}
11+
12+
const routes: UiState[] = [
13+
{ name: 'index', url: '', redirectTo: 'dashboard' },
14+
{ name: 'dashboard', url: '/dashboard', component: DashboardComponent },
15+
{ name: 'detail', url: '/detail/{id}', component: HeroDetailComponent },
16+
{ name: 'heroes', url: '/heroes', component: HeroesComponent }
17+
];
18+
19+
@NgModule({
20+
id: 'AppRoutingModule',
21+
imports: [
22+
'ui.router'
23+
],
24+
})
25+
export class AppRoutingModule {
26+
static config($stateProvider: StateProvider) {
27+
'ngInject';
28+
routes.forEach(route => $stateProvider.state(getNg1StateDeclaration(route)));
29+
}
30+
}
31+
32+
function getNg1StateDeclaration(state: UiState) {
33+
if (state.component && typeof state.component !== 'string') {
34+
state.component = getTypeName(state.component);
35+
}
36+
return state;
37+
}
38+

src/app/app.module.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { StateProvider } from '@uirouter/angularjs';
2-
import { Ng1StateDeclaration } from '@uirouter/angularjs/lib/interface';
3-
import { getTypeName, NgModule } from 'angular-ts-decorators';
1+
import { NgModule } from 'angular-ts-decorators';
2+
import { AppRoutingModule } from './app-routing.module';
43
import { AppComponent } from './app.component';
54
import { DashboardComponent } from './dashboard/dashboard.component';
65
import { HeroDetailComponent } from './hero-detail/hero-detail.component';
@@ -9,23 +8,12 @@ import { HeroService } from './hero.service';
98
import { HeroesComponent } from './heroes/heroes.component';
109
import { MessageService } from './message.service';
1110
import { MessagesComponent } from './messages/messages.component';
12-
1311
import './styles.css';
1412

15-
export interface UiState extends Ng1StateDeclaration {
16-
component?: any;
17-
}
18-
19-
const routes: UiState[] = [
20-
{ name: 'index', url: '', redirectTo: 'dashboard' },
21-
{ name: 'dashboard', url: '/dashboard', component: DashboardComponent },
22-
{ name: 'detail', url: '/detail/{id}', component: HeroDetailComponent },
23-
{ name: 'heroes', url: '/heroes', component: HeroesComponent }
24-
];
25-
2613
@NgModule({
14+
id: 'AppModule',
2715
imports: [
28-
'ui.router'
16+
AppRoutingModule
2917
],
3018
declarations: [
3119
AppComponent,
@@ -36,21 +24,9 @@ const routes: UiState[] = [
3624
HeroSearchComponent
3725
],
3826
providers: [
39-
{ provide: 'heroService', useClass: HeroService },
40-
{ provide: 'messageService', useClass: MessageService }
27+
HeroService,
28+
MessageService,
4129
],
4230
bootstrap: [ AppComponent ]
4331
})
44-
export class AppModule {
45-
static config($stateProvider: StateProvider) {
46-
'ngInject';
47-
routes.forEach((route) => $stateProvider.state(getNg1StateDeclaration(route)));
48-
}
49-
}
50-
51-
function getNg1StateDeclaration(state: UiState) {
52-
if (state.component && typeof state.component !== 'string') {
53-
state.component = getTypeName(state.component);
54-
}
55-
return state;
56-
}
32+
export class AppModule {}

0 commit comments

Comments
 (0)