使用 systemjs 构建器捆绑项目延迟加载 - Angular 2 RC6
Lazy loading with systemjs builder bundled projects - Angular 2 RC6
我在 angular 2 rc6 中将我的延迟加载模块与 systemjs 构建器捆绑在一起,当我 运行 我的应用程序时,我看到所有非延迟加载的模块都在下载(使用 fiddler),那是因为我在 app.module.ts 中导入它们,但是在 app.routing 中使用 "loadChildren" 属性 延迟加载模块的 none 工作,我看到一个白屏 "loading..." 永远挂在那里,模块没有被下载。
这是我的 app.routing:
export const routes: Routes = [
{ path: '', redirectTo: '/strategies', pathMatch: 'full' },
**// NONE OF THE BUNDLES FOR FOLLOWING MODULES ARE BEING DOWNLOADED BY SYSTEM** JS
{ path: 'strategies', loadChildren: 'app/strategy/strategy.module' },
{ path: 'login', loadChildren: 'app/login/login.module' },
{ path: 'crises', loadChildren: 'app/crisis/crisis.module' },
{ path: 'heroes', loadChildren: 'app/hero/hero.module' },
];
export const routing = RouterModule.forRoot(routes);
这是我的 app.module:
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
routing,
CoreModule, ==> **THIS IS BUNDLED TOO AND SYSTEMJS DOWNLOADS IT UP FRONT**
HttpModule,
],
bootstrap: [AppComponent],
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy },
],
})
export class AppModule { }
这是我在 systemjs.config 文件中的捆绑包配置:
bundles: {
'dist/index.js': ['app/*'],
'dist/shared/index.js': ['app/shared/*'],
'dist/core/index.js': ['app/core/*'],
'dist/crisis/index.js': ['app/crisis/*'],
'dist/hero/index.js': ['app/hero/*'],
'dist/strategy/index.js': ['app/strategy/*'],
'dist/login/index.js': ['app/login/*'],
'dist/dependencies.js' : [
'@angular/core/bundles/core.umd.js',
'@angular/common/bundles/common.umd.js',
'@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http/bundles/http.umd.js',
'@angular/router/bundles/router.umd.js',
'@angular/forms/bundles/forms.umd.js',
'angular2-in-memory-web-api/index.js',
'rxjs/*','rxjs/scheduler/*','rxjs/add/*','rxjs/add/operator/*','rxjs/observale/*','rxjs/add/observable/*',
]
}
如有任何提示,我们将不胜感激。
以防万一这对任何人有帮助,我能够解决我的问题。
配置错误。
我更新了我的 systemjs 配置文件,使其具有两种不同的配置,一种用于开发,一种用于 systemjs 构建器包。
production/bundles版本如下:
config.transpiler = 'typescript',
config.map = {
'app': 'app', // this is where your transpiled files live
'@angular': 'node_modules/@angular',
'rxjs': 'node_modules/rxjs',
'typescript': 'node_modules/typescript/lib/typescript.js'
};
config.packages = {
'app': { main: 'main.js', format: 'cjs', defaultExtension: 'js' },
'@angular/core': { main: 'index.js' },
'@angular/common': { main: 'index.js' },
'@angular/compiler': { main: 'index.js' },
'@angular/forms': { main: 'index.js' },
'@angular/http': { main: 'index.js' },
'@angular/platform-browser': { main: 'index.js' },
'@angular/platform-browser-dynamic': { main: 'index.js' },
'@angular/router': { main: 'index.js' },
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
};
config.bundles = {
'dist/index.js': ['app/*'],
'dist/dependencies.js': [
'@angular/core/index.js',
'@angular/common/index.js',
'@angular/compiler/index.js',
'@angular/platform-browser/index.js',
'@angular/platform-browser-dynamic/index.js',
'@angular/http/index.js',
'@angular/router/index.js',
'@angular/forms/index.js',
'angular2-in-memory-web-api/index.js',
'rxjs/*', 'rxjs/scheduler/*', 'rxjs/add/*', 'rxjs/add/operator/*', 'rxjs/observale/*', 'rxjs/add/observable/*',
]
}
并且开发配置保持不变。
更多信息:rc6 config
我在 angular 2 rc6 中将我的延迟加载模块与 systemjs 构建器捆绑在一起,当我 运行 我的应用程序时,我看到所有非延迟加载的模块都在下载(使用 fiddler),那是因为我在 app.module.ts 中导入它们,但是在 app.routing 中使用 "loadChildren" 属性 延迟加载模块的 none 工作,我看到一个白屏 "loading..." 永远挂在那里,模块没有被下载。 这是我的 app.routing:
export const routes: Routes = [
{ path: '', redirectTo: '/strategies', pathMatch: 'full' },
**// NONE OF THE BUNDLES FOR FOLLOWING MODULES ARE BEING DOWNLOADED BY SYSTEM** JS
{ path: 'strategies', loadChildren: 'app/strategy/strategy.module' },
{ path: 'login', loadChildren: 'app/login/login.module' },
{ path: 'crises', loadChildren: 'app/crisis/crisis.module' },
{ path: 'heroes', loadChildren: 'app/hero/hero.module' },
];
export const routing = RouterModule.forRoot(routes);
这是我的 app.module:
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
routing,
CoreModule, ==> **THIS IS BUNDLED TOO AND SYSTEMJS DOWNLOADS IT UP FRONT**
HttpModule,
],
bootstrap: [AppComponent],
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy },
],
})
export class AppModule { }
这是我在 systemjs.config 文件中的捆绑包配置:
bundles: {
'dist/index.js': ['app/*'],
'dist/shared/index.js': ['app/shared/*'],
'dist/core/index.js': ['app/core/*'],
'dist/crisis/index.js': ['app/crisis/*'],
'dist/hero/index.js': ['app/hero/*'],
'dist/strategy/index.js': ['app/strategy/*'],
'dist/login/index.js': ['app/login/*'],
'dist/dependencies.js' : [
'@angular/core/bundles/core.umd.js',
'@angular/common/bundles/common.umd.js',
'@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http/bundles/http.umd.js',
'@angular/router/bundles/router.umd.js',
'@angular/forms/bundles/forms.umd.js',
'angular2-in-memory-web-api/index.js',
'rxjs/*','rxjs/scheduler/*','rxjs/add/*','rxjs/add/operator/*','rxjs/observale/*','rxjs/add/observable/*',
]
}
如有任何提示,我们将不胜感激。
以防万一这对任何人有帮助,我能够解决我的问题。 配置错误。 我更新了我的 systemjs 配置文件,使其具有两种不同的配置,一种用于开发,一种用于 systemjs 构建器包。 production/bundles版本如下:
config.transpiler = 'typescript',
config.map = {
'app': 'app', // this is where your transpiled files live
'@angular': 'node_modules/@angular',
'rxjs': 'node_modules/rxjs',
'typescript': 'node_modules/typescript/lib/typescript.js'
};
config.packages = {
'app': { main: 'main.js', format: 'cjs', defaultExtension: 'js' },
'@angular/core': { main: 'index.js' },
'@angular/common': { main: 'index.js' },
'@angular/compiler': { main: 'index.js' },
'@angular/forms': { main: 'index.js' },
'@angular/http': { main: 'index.js' },
'@angular/platform-browser': { main: 'index.js' },
'@angular/platform-browser-dynamic': { main: 'index.js' },
'@angular/router': { main: 'index.js' },
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
};
config.bundles = {
'dist/index.js': ['app/*'],
'dist/dependencies.js': [
'@angular/core/index.js',
'@angular/common/index.js',
'@angular/compiler/index.js',
'@angular/platform-browser/index.js',
'@angular/platform-browser-dynamic/index.js',
'@angular/http/index.js',
'@angular/router/index.js',
'@angular/forms/index.js',
'angular2-in-memory-web-api/index.js',
'rxjs/*', 'rxjs/scheduler/*', 'rxjs/add/*', 'rxjs/add/operator/*', 'rxjs/observale/*', 'rxjs/add/observable/*',
]
}
并且开发配置保持不变。 更多信息:rc6 config