Skip to content

Commit 2e3b954

Browse files
clydinalan-agius4
authored andcommitted
refactor(@ngtools/webpack): initialize paths plugin in resolve options hook
This change reduces the number of different Webpack resolver factory hooks required to initialize the compiler plugins. Webpack 5 also requires the path plugin to be configured earlier in the process and the options hook provides that ability.
1 parent 9dc094f commit 2e3b954

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

packages/ngtools/webpack/src/angular_compiler_plugin.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -939,12 +939,16 @@ export class AngularCompilerPlugin {
939939
});
940940
}
941941

942-
// tslint:disable-next-line:no-any
943-
(compiler as any).resolverFactory.hooks.resolver
942+
// tslint:disable-next-line: no-any
943+
(compiler as any).resolverFactory.hooks.resolveOptions
944944
.for('normal')
945-
// tslint:disable-next-line:no-any
946-
.tap('angular-compiler', (resolver: any) => {
947-
new TypeScriptPathsPlugin(this._compilerOptions).apply(resolver);
945+
.tap('angular-compiler', (resolveOptions: { plugins: unknown[] }) => {
946+
if (!resolveOptions.plugins) {
947+
resolveOptions.plugins = [];
948+
}
949+
resolveOptions.plugins.push(new TypeScriptPathsPlugin(this._compilerOptions));
950+
951+
return resolveOptions;
948952
});
949953

950954
compiler.hooks.normalModuleFactory.tap('angular-compiler', nmf => {

packages/ngtools/webpack/src/ivy/plugin.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,17 @@ export class AngularWebpackPlugin {
145145
// Example: module -> module__ivy_ngcc
146146
resolverFactoryHooks.resolveOptions
147147
.for('normal')
148-
.tap(PLUGIN_NAME, (resolveOptions: { mainFields: string[] }) => {
148+
.tap(PLUGIN_NAME, (resolveOptions: { mainFields: string[], plugins: unknown[] }) => {
149149
const originalMainFields = resolveOptions.mainFields;
150150
const ivyMainFields = originalMainFields.map((f) => `${f}_ivy_ngcc`);
151151

152+
if (!resolveOptions.plugins) {
153+
resolveOptions.plugins = [];
154+
}
155+
resolveOptions.plugins.push(pathsPlugin);
156+
152157
return mergeResolverMainFields(resolveOptions, originalMainFields, ivyMainFields);
153158
});
154-
155-
resolverFactoryHooks.resolver.for('normal').tap(PLUGIN_NAME, (resolver: {}) => {
156-
pathsPlugin.apply(resolver);
157-
});
158159
});
159160

160161
let ngccProcessor: NgccProcessor | undefined;

0 commit comments

Comments
 (0)