Angular-cli tree-shaking exclude component from removalの質問は非常によく似ていると思うが、何も手に入れられないようだ。Angular2(CLI)ツリーを振ると動的に作成されたNgModuleが削除される
本質的に私はHow can I use/create dynamic template to compile dynamic Component with Angular 2.0?に記載されているような動的コンポーネントファクトリを持っています。
非生産設定の最新のAngular CLIを使用してビルドすると、すべて正常に動作します。私は生産が設定を使用したら、コンテンツを動的に作成したページをロードしようとしたときしかし、私はすぐにブラウザに次のエラーのトレースを取得:ここ
EXCEPTION: No NgModule metadata found for 'e'.
ORIGINAL STACKTRACE:
main.dc05ae9….bundle.js:formatted:4731
Error: No NgModule metadata found for 'e'.
at f (vendor.c18e6df….bundle.js:formatted:76051)
at t.resolve (vendor.c18e6df….bundle.js:formatted:20624)
at t.getNgModuleMetadata (vendor.c18e6df….bundle.js:formatted:20169)
at t._loadModules (vendor.c18e6df….bundle.js:formatted:40474)
at t._compileModuleAndAllComponents (vendor.c18e6df….bundle.js:formatted:40462)
at t.compileModuleAndAllComponentsSync (vendor.c18e6df….bundle.js:formatted:40436)
at e.createComponentFactory (main.dc05ae9….bundle.js:formatted:4789)
は私のコンポーネントファクトリクラスです:
@Injectable()
export class DynamicTypeBuilder {
constructor() {
}
private _cacheOfFactories: {[templateKey: string]: ComponentFactory<any>} = {};
private compiler: Compiler = new JitCompilerFactory([{useDebug: false, useJit: true}]).createCompiler();
public createComponentFactory<COMPONENT_TYPE>(type: any, template: string, additionalModules: any[] = []): Observable<ComponentFactory<COMPONENT_TYPE>> {
let factory = this._cacheOfFactories[template];
if (factory) {
return Observable.of(factory);
}
// unknown template ... let's create a Type for it
let module = this.createComponentModule(type, additionalModules);
// compiles and adds the created factory to the cache
return Observable.of(this.compiler.compileModuleAndAllComponentsSync(module))
.map((moduleWithFactories: ModuleWithComponentFactories<COMPONENT_TYPE>) => {
factory = moduleWithFactories.componentFactories.find(value => value.componentType == type);
this._cacheOfFactories[template] = factory;
return factory;
});
}
protected createComponentModule(componentType: any, additionalModules: any[]): Type<any> {
@NgModule({
imports: [
FormsModule,
ReactiveFormsModule,
BrowserModule,
PipesModule,
...additionalModules
],
declarations: [
componentType
],
schemas:[CUSTOM_ELEMENTS_SCHEMA]
})
class RuntimeComponentModule {
}
return RuntimeComponentModule;
}
}
エラーメッセージの「E」が
createComponentModule
WHIから関数
e()
ある
var _ = function() {
function e() {
this._cacheOfFactories = {},
this.compiler = new i.a([{
useDebug: !1,
useJit: !0
}]).createCompiler()
}
return e.prototype.createComponentFactory = function(e, t, n) {
var i = this;
var _ = this._cacheOfFactories[t];
if (_)
r.Observable.of(_);
var a = this.createComponentModule(e, n);
return r.Observable.of(this.compiler.compileModuleAndAllComponentsSync(a)).map(function(n) {
return _ = n.componentFactories.find(function(t) {
return t.componentType == e
}),
i._cacheOfFactories[t] = _,
_
})
}
,
e.prototype.createComponentModule = function(e, t) {
var n = function() {
function e() {}
return e
}();
return n
}
,
e.ctorParameters = function() {
return []
}
,
e
}()
にtranspiledされ
chは、あなたが見ることができるように、@NgModule
の内容が含まれていても空です。
新しいNgModuleを動的に作成しても、Angular CLIのプロダクションモードを使用するにはどうすればよいですか?
バージョン:
Angular2:2.4.8
角度CLI:1.0.0-beta.32.3
活字体:2.1.6
正しく動作しないのではないでしょうか。コードはコンパイルされていますが、現在は新しい問題があります。 Angularは、新しい 'NgModule'でカスタムインポートされたモジュールを見つけることができません。したがって、上記のFormsModuleの例では、 'ReactiveFormsModule'と' BrowserModule'が見つかりますが、 'PipesModule'は見つかりません。エラーは 'CompileMetadataResolver.getNgModuleMetadata'にあります。 – Sebastian
実際に私は同じ問題を抱えています。 JITコンパイルではデコレータをコンパイルしていないようです。だけでなく、 'RuntimeComponentModule'。コンパイルされた 'main.js'を読み込んだ場合、' PipesModule'のメタデータは含まれません。私はこの時間を続けます。角モジュールがうまくいけば教えてくれるThx。 –
これはすぐにjit + aotを実行しています。 v4で –