简体   繁体   English

在启用 Ivy 的情况下构建 monorepo Angular9 库是不是一个坏主意

[英]Is it a bad idea to build monorepo Angular9 libraries with Ivy enabled

By default, when creating an Angular9 (currently RC) library, the library is built with Ivy being disabled in production mode.默认情况下,在创建 Angular9(当前为 RC)库时,该库是在生产模式下禁用 Ivy 的情况下构建的。 This makes some sense since publishing libraries compiled for Ivy is not (yet) supported.这是有道理的,因为发布为 Ivy 编译的库(尚)不受支持。

In my case however I have a monorepo project and we use libraries to organize our code.然而,就我而言,我有一个 monorepo 项目,我们使用库来组织我们的代码。 The libraries are never pushed to NPM and only used for building the main application in a multi-step build process.这些库永远不会推送到 NPM,仅用于在多步骤构建过程中构建主应用程序。 Building the libraries with Ivy disabled means that the main application build first has to go over all of those libraries and invoke the NGCC to generate the Ivy-versions of the code which seems horribly inefficient and just plain weird.在禁用 Ivy 的情况下构建库意味着主应用程序构建首先必须遍历所有这些库并调用 NGCC 来生成代码的 Ivy 版本,这看起来效率极低而且很奇怪。

The question is: is it a bad idea to just enable Ivy for the production builds of those libraries?问题是:只为这些库的生产版本启用 Ivy 是不是一个坏主意? And if so, why?如果是这样,为什么? What potential problems could pop up?可能会出现哪些潜在问题?

The reason why Google does not yet recommend publishing Ivy libraries is because developers can opt-out of Ivy still. Google 之所以不建议发布 Ivy 库,是因为开发人员仍然可以选择退出 Ivy。 Once they finalize and move everyone to the new build system in angular 10, then they will likely revisit their support of Ivy in published libraries.一旦他们最终确定并将所有人转移到 angular 10 中的新构建系统,那么他们可能会重新审视他们在已发布库中对 Ivy 的支持。

I'd say, if you using Ivy throughout the entire project and not providing them to someone who would be turning Ivy off, then set the libs to Ivy.我想说的是,如果您在整个项目中都使用 Ivy,并且没有将它们提供给会关闭 Ivy 的人,那么将库设置为 Ivy。 Like you said, it is a bit inefficient as it has to convert the libraries up to Ivy.就像你说的,它有点低效,因为它必须将库转换为 Ivy。 Google doesn't recommend publishing. Google 不建议发布。 Doesn't say they don't recommend using Ivy libraries.并不是说他们不建议使用 Ivy 库。

I used https://indepth.dev/the-angular-ivy-guide-for-library-authors/ to fuel my answer.我使用https://indepth.dev/the-angular-ivy-guide-for-library-authors/来为我的答案加油。 I needed to understand why Google recommended against publishing Ivy libs.我需要了解为什么Google 建议不要发布 Ivy 库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM