Angular 10:需要安装后脚本吗?

Angular 10: postinstall script needed?

这可能更像是一个澄清问题:

根据 Ivy 文档(自 Angular 9 起),我们需要在 package.json 中添加一个 postinstall 脚本,如下所示:

"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"

但是,由于我们正在努力缩短构建时间(自 Ivy 以来需要很长时间),我看到一篇关于 entwickler.de 的文章(不幸的是德语),提到,自从 Angular 9.1 我们不再需要这个安装后脚本了。

但是,我在 official docs 中找不到任何关于省略此安装后脚本的信息...

这会是一种可能加快构建时间的方法吗?

postinstallnpm install 之后仅 运行s 是 运行,因此删除它不会加快构建时间(除了可能 运行 npm install 每次).

根据 Angular glossary ngcc 所做的是:

Angular compatibility compiler. If you build your app using Ivy, but it depends on libraries that have not been compiled with Ivy, the CLI uses ngcc to automatically update the dependent libraries to use Ivy.

因此您仍应将其保留为 postinstall 脚本。不过,我不确定的是 --create-ivy-entry-points 标志,因为根据 Angular docs themselves:

Don't use --create-ivy-entry-points as this will cause Node not to resolve the Ivy version of the packages correctly.

但是那句话也出现在 Angular Shell 和 Universal 的标题下。当我升级到 Angular 10 时它没有删除标志,所以我倾向于认为它仍然需要。

我认为不再需要这个了。

https://angular.io/guide/ivy

In version 9, the server builder which is used for App shell and Angular Universal has the bundleDependencies option enabled by default. If you opt-out of bundling dependencies you will need to run the standalone Angular compatibility compiler (ngcc). This is needed because otherwise Node will be unable to resolve the Ivy version of the packages.

我认为它仅适用于SSR构建。而且现在只有ngcc喜欢

{
  "scripts": {
    "postinstall": "ngcc"
  }
}