2016-12-11 19 views
0

私は毎回、角度のあるcliで生成された角度2のアプリですべての遅延ロードを使用しようとします。ルータは動作しますが、追加のチャンクファイルは生成されません。Angular cli lazy loadingが動作しない

これは私のAppModuleです:

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 

import { AppComponent } from './app.component'; 

import { APP_ROUTES } from "./app.routing"; 
import { RouterModule } from '@angular/router'; 

//ng2 bootstrap 
import { Ng2BootstrapModule } from 'ng2-bootstrap/ng2-bootstrap'; 
import { VotesModule } from './votes/votes.module'; 
import { InsertComponent } from './insert/insert.component'; 
import { VotesComponent } from './votes/votes.component'; 

@NgModule({ 
    declarations: [ 
    AppComponent, 
    VotesComponent, 
    InsertComponent 
    ], 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    Ng2BootstrapModule, 
    RouterModule.forRoot(APP_ROUTES), 
    VotesModule 
    ], 
    providers: [], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

私app.routing:

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

import { InsertComponent } from "./insert/insert.component"; 
import { VotesComponent } from "./votes/votes.component"; 

export const APP_ROUTES: Routes = [ 
    { path: '', redirectTo: '/vote', pathMatch: 'full' }, 
    { path: 'vote', component: VotesComponent }, 
    { path: 'auth', component: InsertComponent, loadChildren: 'app/insert/insert.module#InsertModule'} 
]; 

InsertModule:

import { NgModule } from '@angular/core'; 
import { CommonModule } from '@angular/common'; 
import { RouterModule } from "@angular/router"; 

import { INSERTVOTES_ROUTES } from './insert-vote.routing'; 

import { InsertListComponent } from './insert-list/insert-list.component'; 
import { InsertVotersComponent } from './insert-voters/insert-voters.component'; 

@NgModule({ 
    imports: [ 
    CommonModule, 
    RouterModule.forChild(INSERTVOTES_ROUTES) 
    ], 
    declarations: [ InsertListComponent, InsertVotersComponent] 
}) 
export class InsertModule { } 

とインサート-vote.routing:

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

import { InsertVotersComponent } from "./insert-voters/insert-voters.component"; 
import { InsertListComponent } from "./insert-list/insert-list.component"; 

export const INSERTVOTES_ROUTES: Routes = [ 
    { path: '', redirectTo: 'insert', pathMatch: 'full' }, 
    { path: 'insert', component: InsertVotersComponent }, 
    { path: 'voters', component: InsertListComponent } 
]; 

this is the screenshot in wich there isn't chunk file

インストールする必要があるいくつかの依存関係はありますか?または任意のアイデア? AppModule に

{ 
    "name": "votes", 
    "version": "0.0.0", 
    "license": "MIT", 
    "angular-cli": {}, 
    "scripts": { 
    "start": "node ./bin/www", 
    "lint": "tslint \"src/**/*.ts\"", 
    "test": "ng test", 
    "pree2e": "webdriver-manager update", 
    "e2e": "protractor" 
    }, 
    "private": true, 
    "dependencies": { 
    "@angular/common": "2.2.3", 
    "@angular/compiler": "2.2.3", 
    "@angular/core": "2.2.3", 
    "@angular/forms": "2.2.3", 
    "@angular/http": "2.2.3", 
    "@angular/platform-browser": "2.2.3", 
    "@angular/platform-browser-dynamic": "2.2.3", 
    "@angular/router": "3.2.3", 
    "bcryptjs": "^2.3.0", 
    "body-parser": "^1.15.2", 
    "bootstrap": "^3.3.7", 
    "cookie-parser": "^1.4.3", 
    "core-js": "^2.4.1", 
    "express": "^4.14.0", 
    "jsonwebtoken": "^7.2.1", 
    "mongoose": "^4.7.2", 
    "mongoose-unique-validator": "^1.0.3", 
    "morgan": "^1.7.0", 
    "ng2-bootstrap": "^1.1.16", 
    "rxjs": "5.0.0-beta.12", 
    "serve-favicon": "^2.3.2", 
    "ts-helpers": "^1.1.1", 
    "zone.js": "^0.6.23" 
    }, 
    "devDependencies": { 
    "@angular/compiler-cli": "2.2.3", 
    "@types/jasmine": "2.5.38", 
    "@types/node": "^6.0.42", 
    "angular-cli": "1.0.0-beta.22-1", 
    "codelyzer": "~2.0.0-beta.1", 
    "jasmine-core": "2.5.2", 
    "jasmine-spec-reporter": "2.5.0", 
    "karma": "1.2.0", 
    "karma-chrome-launcher": "^2.0.0", 
    "karma-cli": "^1.0.1", 
    "karma-jasmine": "^1.0.2", 
    "karma-remap-istanbul": "^0.2.1", 
    "protractor": "4.0.9", 
    "ts-node": "1.2.1", 
    "tslint": "^4.0.2", 
    "typescript": "~2.0.3", 
    "webdriver-manager": "10.2.5" 
    } 
} 

答えて

0

削除 "InsertComponent" 宣言からと削除: がここにあり、私のpackage.jsonである: "APP_ROUTES" から "コンポーネントInsertComponent" を、私はあなたがLazy-Loading route configuration

+0

はそれを行ったが何も変わっていないあなたにインサートvote.routing遅延ロードされたルートから

{ path: 'auth', loadChildren:'app/insert/insert.module#InsertModule'} 

を成分を除去しAPP_ROUTESを更新し、更新する必要があり、それが動作しませんが、何のチャンク – user3706153

0

を見てみましょう示唆しますあなたのAppModuleは、loadChildren経由でInsertModuleをロードするルートを持つ必要があります。それで、CLIが別々のバンドルを生成する方法です。

0

あなたは

{ path: '', component: InsertComponent }, 
{ path: 'insert', component: InsertVotersComponent }, 
{ path: 'voters', component: InsertListComponent } 
関連する問題