2017-06-08 40 views
1

版本:如何將路由中的lazyload模塊更改爲正常模塊?

ng version: 
@angular/cli: 1.0.0-rc.1 
node: 6.10.2 
os: win32 x64 
@angular/common: 4.1.1 
@angular/compiler: 4.1.1 
@angular/compiler-cli: 4.1.1 
@angular/core: 4.1.1 
@angular/forms: 4.1.1 
@angular/http: 4.1.1 
@angular/platform-browser: 4.1.1 
@angular/platform-browser-dynamic: 4.1.1 
@angular/router: 4.1.1 
@angular/cli: 1.0.0-rc.1 

我的項目中使用,以使用路線lazyload模塊,如:

import { NgModule } from '@angular/core'; 
import { Routes, RouterModule } from '@angular/router'; 

export const routes: Routes = [ 
    { path: 'global-config', loadChildren: 'app/modules/act-widget/main.module#GlobalConfigModule' } 
]; 

但是,我們有太多的lazyload模塊。它使我們的建設過程緩慢(92%塊資產優化)。 所以我們做出放棄lazyload模塊的決定。

但是,當我改成這樣:出現

import { NgModule } from '@angular/core'; 
import { Routes, RouterModule } from '@angular/router'; 
import {GlobalConfigModule} from '../modules/global-config/global-config.module'; 

export const routes: Routes = [ 
    { path: 'global-config', loadChildren:() => GlobalConfigModule } 
]; 

錯誤:

ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 12:42 in the original .ts file), resolving symbol routes in E:/pgg_oa/src/app/container/container-routing.module.ts, resolving symbol AppRoutingModule in E:/pgg_oa/src/app/container/container-routing.module.ts, resolving symbol AppRoutingModule in E:/pgg_oa/src/app/container/container-routing.module.ts, resolving symbol AppRoutingModule in E:/pgg_oa/src/app/container/container-routing.module.ts 

我的問題是:

我怎樣才能改變我們的lazyload模塊進入正常的模塊以最少的成本?

+0

只需將您的cli更新到最新版本,它就不會再那麼慢了。 –

回答

1

您應該創建一個導出函數,並將其用作loadChildren的值。問題是,你必須創建一個函數的每一個模塊:

export function getGlobalConfigModule(): typeof GlobalConfigModule { 
    return GlobalConfigModule; 
} 

export const routes: Routes = [ 
    { path: 'global-config', loadChildren: getGlobalConfigModule} 
]; 

應用程序的初始啓動時間會慢很多,雖然,我不知道你想做出這樣的決定。由於AoT編譯完成,構建過程需要很長時間。也許投資於具有高I/O的新磁盤將會提高構建時間