编译生产版本时出现Angular2 AOT问题 - app模块问题

时间:2016-12-11 15:18:21

标签: javascript angular systemjs aot angular2-aot

编译生产版本时出现Angular2 AOT问题 - 应用程序模块问题

我正在使用angular2,typescript,html5和systemjs

这是我正在使用的angular2种子应用:https://github.com/mgechev/angular-seed

当我这样做git bash命令时:npm运行serve.prod.exp并为AOT创建一个构建包。然后我在git bash中收到错误。

这是我得到的错误AOT构建错误:

enter image description here

这是我的app.module:

import { NgModule } from '@angular/core';
import { routes } from './app.routes';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { FormsModule} from '@angular/forms';
import { APP_BASE_HREF, CommonModule, Location } from '@angular/common';
import { RouterModule } from '@angular/router';
import { MetadataModule } from 'ng2-metadata';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { CanActivateViaAuthGuard } from './guard.module';

//Pages
import { HomeModule } from './components/home/home.module';
import { ContactModule } from './components/contact/contact.module';
import { ForgotPasswordModule } from './components/forgotPassword/forgotPassword.module';
import { LoginModule } from './components/login/login.module';
import { RegisterModule } from './components/register/register.module';
import { NewJobsModule } from './components/newJobs/newJobs.module';
import { NewJobModule } from './components/newJob/newJob.module';
import { BlogModule } from './components/blog/blog.module';
import { BlogArticleModule } from './components/blogArticle/blogArticle.module';
import { SocialRegisterModule } from './components/socialRegister/socialRegister.module';
import { AdminModule } from './components/admin/admin.module';
import { ApplicationsModule } from './components/applications/applications.module';
import { ChangeEmailModule } from './components/changeEmail/changeEmail.module';
import { ChangePasswordModule } from './components/changePassword/changePassword.module';
import { CompanyModule } from './components/company/company.module';
import { CreateJobModule } from './components/createJob/createJob.module';
import { DashboardModule } from './components/dashboard/dashboard.module';
import { HelpModule } from './components/help/help.module';
import { InviteModule } from './components/invite/invite.module';
import { JobModule } from './components/job/jobs.module';
import { MessagesModule } from './components/messages/messages.module';
import { MessengerModule } from './components/messenger/messenger.module';
import { ProfileModule} from './components/profile/profile.module';
import { SearchJobsModule } from './components/searchJobs/searchJobs.module';
import { SearchUsersModule } from './components/searchUsers/searchUsers.module';
import { UserApplicationsModule } from './components/userApplications/userApplications.module';
import { SiteMapModule } from './components/sitemap/sitemap.module';
import { SplashModule } from './components/splash/splash.module';
import { PageNotFoundModule } from './components/pageNotFound/pageNotFound.module';
import { TermsModule } from './components/terms/terms.module';
import { PrivacyModule } from './components/privacy/privacy.module';
import { CompetitionModule } from './components/competition/competition.module';
import { FaqModule } from './components/faq/faq.module';
import { AboutModule } from './components/about/about.module';
import { DBSModule } from './components/dbs/dbs.module';
import { Module400 } from './components/400/400.module';
import { Module404 } from './components/404/404.module';
import { Module500 } from './components/500/500.module';

//Services and modules
import { AuthService } from './services/authService/authService';
import { MessageService } from './services/messageService/messageService';
import { UserService } from './services/userService/userService';
import { UserProfile } from './models/profile/profile';
import { JobService } from './services/jobService/jobService';
import { Job } from './models/job/job';
import { Environment } from './models/environment/environment';

//Shared
import { HeaderComponent } from './components/shared/header/header.module';
import { HeaderCompanyComponent } from './components/shared/headerCompany/headerCompany.module';
import { HeaderUserComponent } from './components/shared/headerUser/headerUser.module';
import { SideMenuUserComponent } from './components/shared/sideMenuUser/sideMenuUser.module';
import { SideMenuCompanyComponent } from './components/shared/sideMenuCompany/sideMenuCompany.module';
import { FooterModule } from './components/shared/footer/footer.module';

@NgModule({
  imports: [BrowserModule, FormsModule, RouterModule, CommonModule, HttpModule, FooterModule, MetadataModule.forRoot(), RouterModule.forRoot(routes), 
  HomeModule, 
  ContactModule, 
  ForgotPasswordModule, 
  LoginModule,
  RegisterModule,
  NewJobsModule,
  NewJobModule,
  BlogModule,
  BlogArticleModule,
  SiteMapModule,
  SocialRegisterModule,
  ProfileModule,
  SplashModule,
  CompanyModule,
  ChangeEmailModule,
  ChangePasswordModule,
  DashboardModule,
  HelpModule,
  InviteModule,
  MessagesModule,
  MessengerModule,
  UserApplicationsModule,
  SearchUsersModule,
  ApplicationsModule,
  JobModule,
  CreateJobModule,
  SearchJobsModule,
  TermsModule,
  PrivacyModule,
  FaqModule,
  Module400,
  Module500,
  Module404,
  DBSModule,
  CompetitionModule,
  PageNotFoundModule,
  AboutModule,
  AdminModule
  ],
  declarations: [AppComponent, HeaderComponent, HeaderUserComponent, SideMenuUserComponent, SideMenuCompanyComponent, HeaderCompanyComponent],
  providers: [{
    provide: APP_BASE_HREF,
    useValue: '<%= APP_BASE %>'},
    AuthService,
    UserService,
    UserProfile,
    JobService,
    Job,
    MessageService,
    Environment,
    CanActivateViaAuthGuard
  ],
  bootstrap: [AppComponent]
})

export class AppModule { }

*如果您需要查看我的应用中的代码,请告诉我。

我只想构建这个应用程序,这样我就可以在AOT中运行它,并在第一次加载应用程序时获得快速加载时间。目前它的加载时间为4秒。

应用路线:

import { Routes } from '@angular/router';

import { HomeRoutes } from './components/home/index';
import { ContactRoutes } from './components/contact/index';
import { ForgotPasswordRoutes } from './components/forgotPassword/index';
import { LoginRoutes } from './components/login/index';
import { RegisterRoutes } from './components/register/index';
import { NewJobsRoutes } from './components/newJobs/index';
import { NewJobRoutes } from './components/newJob/index';
import { BlogRoutes } from './components/blog/index';
import { BlogArticleRoutes } from './components/blogArticle/index';
import { SocialRegisterRoutes } from './components/socialRegister/index';
import { AdminRoutes } from './components/admin/index';
import { ApplicationsRoutes } from './components/applications/index';
import { ChangeEmailRoutes } from './components/changeEmail/index';
import { ChangePasswordRoutes } from './components/changePassword/index';
import { CompanyRoutes } from './components/company/index';
import { CreateJobRoutes } from './components/createJob/index';
import { DashboardRoutes } from './components/dashboard/index';
import { HelpRoutes } from './components/help/index';
import { InviteRoutes } from './components/invite/index';
import { JobRoutes } from './components/job/index';
import { MessagesRoutes } from './components/messages/index';
import { MessengerRoutes } from './components/messenger/index';
import { ProfileRoutes } from './components/profile/index';
import { SearchJobsRoutes } from './components/searchJobs/index';
import { SearchUsersRoutes } from './components/searchUsers/index';
import { UserApplicationsRoutes } from './components/userApplications/index';
import { SiteMapRoutes } from './components/sitemap/index';
import { TermsRoutes } from './components/terms/index';
import { FAQRoutes } from './components/faq/index';
import { PrivacyRoutes } from './components/privacy/index';
import { CompetitionRoutes } from './components/competition/index';
import { PageNotFoundRoutes } from './components/pageNotFound/index';
import { AboutRoutes } from './components/about/index';
import { Routes400 } from './components/400/index';
import { Routes404 } from './components/404/index';
import { Routes500 } from './components/500/index';
import { DBSRoutes } from './components/dbs/index';

export const routes: Routes = [
...HomeRoutes, 
...ContactRoutes,
...ForgotPasswordRoutes,
...LoginRoutes,
...RegisterRoutes,
...NewJobsRoutes,
...NewJobRoutes,
...BlogRoutes,
...BlogArticleRoutes,
...SiteMapRoutes,
...SocialRegisterRoutes,
...ProfileRoutes,
...CompanyRoutes,
...ChangeEmailRoutes,
...ChangePasswordRoutes,
...DashboardRoutes,
...HelpRoutes,
...InviteRoutes,
...MessagesRoutes,
...MessengerRoutes,
...UserApplicationsRoutes,
...SearchUsersRoutes,
...ApplicationsRoutes,
...JobRoutes,
...CreateJobRoutes,
...SearchJobsRoutes,
...AdminRoutes,
...TermsRoutes,
...PrivacyRoutes,
...FAQRoutes,
...CompetitionRoutes,
...Routes400,
...Routes404,
...Routes500,
...DBSRoutes,
...AboutRoutes,
...PageNotFoundRoutes
];

这是引导程序的主文件:

import { enableProdMode } from '@angular/core';
// The browser platform with a compiler
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
// The app module
import { AppModule } from './app.module';

if (String('<%= BUILD_TYPE %>') === 'prod') { enableProdMode(); }

platformBrowserDynamic().bootstrapModule(AppModule/*, options*/);

0 个答案:

没有答案