我将SystemJsNgModuleLoader
用于延迟加载模块:
export function createJitCompiler() {
return new JitCompilerFactory().createCompiler([{useJit: true}]);
}
export function createLoader(_compiler: Compiler) {
return new ModuleLoader(_compiler);
}
export class ModuleLoader implements NgModuleFactoryLoader {
private systemJsNgModuleLoader: SystemJsNgModuleLoader;
constructor(
private readonly compiler: Compiler,
@Optional() config?: SystemJsNgModuleLoaderConfig
) {
this.systemJsNgModuleLoader = new SystemJsNgModuleLoader(compiler, {
factoryPathPrefix: "js",
factoryPathSuffix: ""
});
}
public load(path: string) {
return this.systemJsNgModuleLoader.load(path);
}
}
@NgModule({
imports: [
BrowserModule,
CoreModule.forRoot()
],
providers: [
{provide: Compiler, useFactory: createJitCompiler},
{provide: NgModuleFactoryLoader, useClass: ModuleLoader},
provideRoutes([
{loadChildren: "../modules/test/test.module#TestModule"}
])
]
})
export class AppModule {
constructor(private injector: Injector,
private moduleLoader: NgModuleFactoryLoader,
private compiler: Compiler) {
}
ngDoBootstrap(appRef: ApplicationRef) {
this.moduleLoader.load("../modules/test/test.module#TestModule").then((moduleFactory: NgModuleFactory<any>) => {
this.compiler.compileModuleAndAllComponentsAsync(moduleFactory.moduleType)
.then((compiled) => {
//TODO
})
});
}
}
AOT编译后,我的文件包含在/js
目录中,但是moduleLoader
尝试从站点根目录而不是从/js
文件夹下载模块。我的班级ModuleLoader
无法将SystemJsNgModuleLoaderConfig
设置为班级SystemJsNgModuleLoader
,以设置用于加载模块的根目录。
告诉我如何为SystemJsNgModuleLoaderConfig
设置SystemJsNgModuleLoader
?