Skip to content

Commit b3d6d50

Browse files
kapunahelewongkara
authored andcommitted
docs: add ngcc postinstall migration doc (angular#33328)
PR Close angular#33328
1 parent 1b8b04c commit b3d6d50

3 files changed

Lines changed: 85 additions & 0 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ testing/** @angular/fw-test
887887
/aio/content/guide/migration-injectable.md @angular/fw-docs-packaging @angular/framework-global-approvers @angular/framework-global-approvers-for-docs-only-changes
888888
/aio/content/guide/migration-localize.md @angular/fw-docs-packaging @angular/framework-global-approvers @angular/framework-global-approvers-for-docs-only-changes
889889
/aio/content/guide/migration-module-with-providers.md @angular/fw-docs-packaging @angular/framework-global-approvers @angular/framework-global-approvers-for-docs-only-changes
890+
/aio/content/guide/migration-ngcc.md @angular/fw-docs-packaging @angular/framework-global-approvers @angular/framework-global-approvers-for-docs-only-changes
890891

891892

892893
# ================================================

aio/content/guide/deprecations.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ See the [dedicated migration guide for adding missing `@Injectable` decorators](
366366
### Migrating `ModuleWithProviders`
367367

368368
See the [dedicated migration guide for `ModuleWithProviders`](guide/migration-module-with-providers).
369+
{@a ngcc-migration}
370+
### Migrating to `ngcc` npm `postinstall` script
371+
372+
See the [dedicated migration guide for `ngcc` npm `postinstall` script](guide/migration-ngcc).
373+
369374

370375

371376
{@a removed}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Migration to `ngcc` npm `postinstall` script
2+
3+
## What does this schematic do?
4+
5+
This schematic adds an [Angular compatibility compiler](guide/ngcc), or `ngcc`, invocation to npm/yarn's `postinstall` script in the `package.json` of an Angular CLI workspace.
6+
This script is invoked after each execution of `npm install` and modifies `node_modules` by converting any found Angular libraries to a format that is compatible with Angular version 9.
7+
8+
An example diff might look like the following:
9+
10+
**Before:**
11+
12+
```json
13+
"scripts": {
14+
"ng": "ng",
15+
"start": "ng serve",
16+
"build": "ng build",
17+
"test": "ng test",
18+
"lint": "ng lint",
19+
"e2e": "ng e2e"
20+
},
21+
```
22+
23+
**After:**
24+
25+
```json
26+
"scripts": {
27+
"ng": "ng",
28+
"start": "ng serve",
29+
"build": "ng build",
30+
"test": "ng test",
31+
"lint": "ng lint",
32+
"e2e": "ng e2e",
33+
"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"
34+
},
35+
```
36+
37+
If the `package.json` already contains a `postinstall` script, then the `ngcc` invocation will be prepended to the current command:
38+
39+
**Before:**
40+
```json
41+
"scripts": {
42+
...
43+
"postinstall": "some-command"
44+
},
45+
```
46+
47+
**After:**
48+
```json
49+
"scripts": {
50+
...
51+
"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points && some-command"
52+
},
53+
```
54+
55+
56+
## Why is this migration necessary?
57+
58+
This migration is a build performance optimization that enables `ngcc` to parallelize the compilation of npm libraries.
59+
An application build performed via CLI's `ng build` should succeed regardless of this `postinstall` script being installed, because the CLI has `ngcc` built-in.
60+
However, this built-in `ngcc` can't parallelize the compilation of multiple libraries, and therefore often takes considerably longer to run.
61+
62+
63+
## Can I customize the `ngcc` options in the `postinstall` script?
64+
65+
By default the `postinstall` script invokes `ngcc` with options to compile only the most commonly needed library formats.
66+
For some projects, especially those that depend on the CommonJS distribution of Angular (for example, Angular Universal apps), it might be beneficial to modify the `postinstall` script to also compile the CommonJS distribution of the library:
67+
68+
```json
69+
"scripts": {
70+
...
71+
"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points && ngcc --properties main --create-ivy-entry-points"
72+
},
73+
```
74+
75+
For the full set of options run `npx ngcc --help` or `yarn ngcc --help`.
76+
77+
## Will libraries compiled with `ngcc` still be compatible with Angular version 8?
78+
79+
Yes, the migration causes `ngcc` to be invoked with the `--create-ivy-entry-points` flag, which ensures that the `ngcc` compilation is non-destructive, so the same `node_modules` can be used with Angular version 8 and version 9.

0 commit comments

Comments
 (0)