为什么我不应该发布用 Ivy 编译的库?
Why shouldn't I publish libraries compiled with Ivy?
我有一个我们公司使用的工具包库。目前,我们正在将所有项目迁移到 angular 11
。所以很自然地,我们也将工具包库更新为 Angular 11。
从 ng11 开始,Ivy 是默认引擎,我认为打开它是个好主意,这样我们的应用程序就不需要用 ngcc
编译它了。所以我在 package.json
:
中设置了这个
"angularCompilerOptions": { "enableIvy": true },
但是当我试图推动它时,我看到了错误:
npm ERR! my-lib@0.0.1 prepublishOnly: node --eval
"console.error('ERROR: Trying to publish a package that has been
compiled by Ivy. This is not allowed.\nPlease delete and rebuild the
package, without compiling with Ivy, before attempting to
publish.\n')" && exit 1
似乎这个错误 生成到 dist 编译代码中 如果我用 Ivy 编译,它会阻止我推送到我们的 nexus。
在此处找到此报告和官方答案:
https://github.com/angular/angular/issues/37973
我的问题是:这是为什么?为什么不推荐用ivy发布呢?这样 lib 用 ViewEngine
编译然后安装(在我们的 angular 11 个项目中)作为依赖只用 ngcc
预编译以与 Ivy 兼容,这看起来像一个对我来说是不好的做法。
我觉得我在这里误解了什么,有人可以给我解释一下吗?
如上所述his answer on that github link
The reason is actually forward compatibility. If we allow ivy compiled
libraries to be published right now, then we lock ourselves into a
very specific use of the ivy instruction set and data structures. This
would affect us from being able to make implementation changes that
would fix bugs, improvement performance, reduce code size etc. By
keeping the ivy internals private we can be more agile going forward.
The current way to achieve this is by requiring ViewEngine compiled
code (since this leaves the decorator information in place), which
ngcc is able to convert to ivy code at library installation/
application build time. Going forward we are looking into a partially
compiled library format that will have the best of both worlds: not
requiring a lengthy ngcc build step, but also not exposing the
internals of the ivy runtime.
我有一个我们公司使用的工具包库。目前,我们正在将所有项目迁移到 angular 11
。所以很自然地,我们也将工具包库更新为 Angular 11。
从 ng11 开始,Ivy 是默认引擎,我认为打开它是个好主意,这样我们的应用程序就不需要用 ngcc
编译它了。所以我在 package.json
:
"angularCompilerOptions": { "enableIvy": true },
但是当我试图推动它时,我看到了错误:
npm ERR! my-lib@0.0.1 prepublishOnly: node --eval "console.error('ERROR: Trying to publish a package that has been compiled by Ivy. This is not allowed.\nPlease delete and rebuild the package, without compiling with Ivy, before attempting to publish.\n')" && exit 1
似乎这个错误 生成到 dist 编译代码中 如果我用 Ivy 编译,它会阻止我推送到我们的 nexus。
在此处找到此报告和官方答案:
https://github.com/angular/angular/issues/37973
我的问题是:这是为什么?为什么不推荐用ivy发布呢?这样 lib 用 ViewEngine
编译然后安装(在我们的 angular 11 个项目中)作为依赖只用 ngcc
预编译以与 Ivy 兼容,这看起来像一个对我来说是不好的做法。
我觉得我在这里误解了什么,有人可以给我解释一下吗?
如上所述his answer on that github link
The reason is actually forward compatibility. If we allow ivy compiled libraries to be published right now, then we lock ourselves into a very specific use of the ivy instruction set and data structures. This would affect us from being able to make implementation changes that would fix bugs, improvement performance, reduce code size etc. By keeping the ivy internals private we can be more agile going forward.
The current way to achieve this is by requiring ViewEngine compiled code (since this leaves the decorator information in place), which ngcc is able to convert to ivy code at library installation/ application build time. Going forward we are looking into a partially compiled library format that will have the best of both worlds: not requiring a lengthy ngcc build step, but also not exposing the internals of the ivy runtime.