Angular-cli摇树排除了将组件从移除中移除 [英] Angular-cli tree-shaking exclude component from removal

查看:48
本文介绍了Angular-cli摇树排除了将组件从移除中移除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular-cli开发一个angular 2应用

I'm developing an angular 2 app with angular-cli

angular 2   - 2.1.1
angular-cli - 1.0.0-beta.18

该应用程序的一项功能是它列出所有事件,然后单击一个事件将在3个选项卡中显示事件详细信息-概述,照片和照片;门票

One functionality of the app is it lists down all the events and clicking on one event displays event details in 3 tabs - Overview, Photos & Tickets

我开发此方法的方式是将所有事件存储在数据库中,并且概述",照片"和票证"选项卡的内容也位于数据库中.因此,通过这种方式,我只能拥有一个组件,该组件呈现3个选项卡并填充从DB提取的每个选项卡内容.现在有趣的是,大多数事件将具有相同的布局和部分,但是对于某些事件可能需要不同的布局.因此,要解决此问题以及2个选项卡内容(概述,照片,票证)中的每一个,我还要存储将呈现此事件的组件的名称.

The way I've developed this is I've all the events stored in my db and also the content for Overview, Photos and Tickets tabs are in DB. So this way I can just have one component which renders 3 tabs and populates each tab content fetched from DB. Now the interesting bit is most of the events will have same layout and sections, but for some there can be different layout required. So to address this what I'm doing is along with each of the 2 tabs content (overview, photos, tickets), I also store the name of the component which will render this event.

以某种方式设法使用ComponentFactoryResolverViewContainerRef从所有组件的名称中获取了该组件可以正常工作,但是当我尝试构建生产环境时出现问题,其中angular-cli会引起摇晃,并且我的所有组件实际上并未在代码中引用/导入,而是根据数据动态创建/呈现从db检索到的数据被删除,由于找不到这些组件,我的应用程序崩溃了.

I somehow managed to get the component from the name of the component using ComponentFactoryResolver and ViewContainerRef and all works fine, but problem arises when I try to make a build for production environment where angular-cli kicks tree-shaking and with that all my components which are not actually referenced/imported in the code but are dynamically created/rendered based on the data retrieved from db are dropped and my app crashes since it cannot find those components.

所以我的问题是/是

  1. 有没有一种方法可以防止某些组件在摇树时被删除/掉落? 一种.如果是,那怎么办?
    b.如果否,那还有什么选择?
  1. Is there a way to exclude certain components from getting removed/dropped during tree shaking? a. If YES, then how?
    b. If NO then what's the alternative?

推荐答案

将这些组件添加到

@NgModule({
  entryComponents: [...],
  ...
})

https://angular.io/docs/ts/latest/api/core/index/NgModule-interface.html#!#entryComponents-anchor

这篇关于Angular-cli摇树排除了将组件从移除中移除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆