为什么在进行AOT构建时不能在导出中使用简单的数组方法

时间:2018-12-19 13:07:42

标签: angular ionic3 angular-aot

我制作了一个很大的Angular应用程序(Angular 5和Ionic 3),并将其构建到Android应用程序中。在开发过程中,我一直使用ionic cordova build,但是现在我想使用ionic cordova build --prod来制作一个好的生产版本(启动期间不应有约15秒的白屏)。

不幸的是,由于AOT编译器不断抛出有关AppModule的错误,我必须在应用程序中更改很多结构。我解决的大多数错误原因均与出口和我自己的模块有关。

我的应用程序由许多较小的“应用程序”组成,用户可以在其中使用菜单进行切换。点击即可加载较小的应用程序。为了减少开发人员必须进行导入和导出的“配置”数量,我将这些较小的应用程序的组件包装在一个对象中,该对象还包含一些常规信息,例如应用程序名称,说明等。这些对象被收集放在一个文件中并放在列表中。

应用一

@Component({
  selector: 'app-one',
  templateUrl: 'app-one.component.html'
})
export class AppOneComponent {
  ...
}

export const AppOne: AppConfiguration = {
  id: 10,
  name: 'App One',
  description: '...',
  component: AppOneComponent
}

将所有应用收集到一个“ module.ts”文件中,该文件将导入到AppModule中

import { AppOne } from './app-one/app-one.component';
import { AppTwo } from './app-two/app-two.component';
import { AppThree } from './app-three/app-three.component';

// This apps list will be imported in the app menu's component to show all apps, 
// and use their component property to load the app once clicked
export const apps = [
  AppOne,
  AppTwo,
  AppThree,
];

// This components list will be imported by the AppModule so all the 
// components are known in the app
export const components = apps.map(a => a.component);

AppModule

import * as MyApps from './apps/module';

@NgModule({
  declarations: [
    ...MyApps.components
  ],
  ...
  ...
})
export class AppModule { }

但是现在的问题是,AOT编译器显然不喜欢.map()(可能还有其他方法)并返回错误。默认的JIT编译器对此没有任何问题。

  

模块'AppModule在C:/code/app/src/app/app.module.ts'中声明的意外值'null'

我已经确认所有组件都不是NULL或没有任何看起来像是空值/属性的组件,所以情况并非如此。如果我自己列出清单,那没关系。

export const components = [
  AppOne.component,
  AppTwo.component,
  AppThree.component,
];

必须像这样写出所有导出内容,这会增加很多开销,尤其是随着添加更多应用程序的列表随着时间的增长而增长。这些应用程序还具有子组件,这些子组件也可以使用相同的方式进行配置并添加到主AppModule中(为简单起见,我将其保留在示例中)。有什么方法可以让我继续使用更简单的导入/导出形式?

0 个答案:

没有答案
相关问题