Angular 10: postinstall script needed?

9k Views Asked by At

This is maybe more a clarification question:

According to the docs for Ivy (since Angular 9) we need to add a postinstall script into our package.json, which looks like this:

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

However, since we're trying to improve our build time (which takes ages since Ivy), I came across an article on entwickler.de (unfortunately in german), mentioning, that since Angular 9.1 we don't need this postinstall script anymore.

However, I cannot find anything in the official docs about omitting this postinstall script...

Would that be a way to potentially speed up the build time?

2

There are 2 best solutions below

1
On BEST ANSWER

postinstall only runs after a npm install is run, so removing it wouldn't speed up build times (except maybe a build pipeline that ran npm install every time).

According to the Angular glossary What ngcc does is:

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.

So you should still keep it as a postinstall script. What I'm unsure of, though, is the --create-ivy-entry-points flag, because according to the 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.

But that quote also comes under a heading of Angular Shell and Universal. It didn't remove the flag when I upgraded to Angular 10, so I tend to think it's still needed.

0
On

I don't think this is needed anymore.

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.

I think it is only for SSR build. And it is only ngcc now like

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