Skip to content

Commit 25ef78e

Browse files
gkalpakdgp1130
authored andcommittedApr 10, 2020
fix(@ngtools/webpack): give higher priority to ivy-specific entry-points
When Ivy is enabled in an app, the app's dependencies are processed by ngcc (the Angular compatibility compiler), which will generate new Ivy-compatible entry-points in each package. To allow webpack find those entry-points, it will add references to them in `package.json`, named after the original property with the `_ivy_ngcc` suffix. So, for example, `es2015` and `module` will become `es2015_ivy_ngcc` and `module_ivy_ngcc`. Previously, the `mainFields` passed to webpack would give higher priority to an Ivy entry-point compared to the corresponding non-ivy entry-point but not compared to other entry-points. For example, `es2015, module` would becode `es2015_ivy_ngcc, es2015, module_ivy_ngcc, module`. This could mean that `es2015` would be preferred over `module_ivy_ngcc`, even though the former is probably not Ivy-ready. Generally, if `es2015` exists and has a higher priority than `module`, then `es2015_ivy_ngcc` would be generated before (or instead of) `module_ivy_ngcc`, but this can be changed using an ngcc configuration file (`ngcc.config.js`). This commit fixes this by ensuring that any `_ivy_ngcc` entry-point is considered before any of the original entry-points in the `mainFields` list. NOTE: While it is possible that a format is Ivy-compatible without bhaving an `_ivy_ngcc` suffix (e.g. if the user does a manual ngcc pass without `--create-ivy-entry-points`), it is quite unlikely to happen and even if it does, choosing a different format should be OK. (cherry picked from commit c7c574a)
1 parent 8c71aff commit 25ef78e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎packages/ngtools/webpack/src/angular_compiler_plugin.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -911,18 +911,18 @@ export class AngularCompilerPlugin {
911911
// When Ivy is enabled we need to add the fields added by NGCC
912912
// to take precedence over the provided mainFields.
913913
// NGCC adds fields in package.json suffixed with '_ivy_ngcc'
914-
// Example: module -> module__ivy_ngcc
914+
// Example: module -> module_ivy_ngcc
915915
// tslint:disable-next-line:no-any
916916
(compiler as any).resolverFactory.hooks.resolveOptions
917917
.for('normal')
918918
// tslint:disable-next-line:no-any
919919
.tap('WebpackOptionsApply', (resolveOptions: any) => {
920-
const mainFields = (resolveOptions.mainFields as string[])
921-
.map(f => [`${f}_ivy_ngcc`, f]);
920+
const originalMainFields: string[] = resolveOptions.mainFields;
921+
const ivyMainFields = originalMainFields.map(f => `${f}_ivy_ngcc`);
922922

923923
return {
924924
...resolveOptions,
925-
mainFields: flattenArray(mainFields),
925+
mainFields: [...ivyMainFields, ...originalMainFields],
926926
};
927927
});
928928
}

0 commit comments

Comments
 (0)
Please sign in to comment.