@@ -10,7 +10,6 @@ import type { CompilerHost, CompilerOptions, NgtscProgram } from '@angular/compi
1010import  {  strict  as  assert  }  from  'assert' ; 
1111import  *  as  ts  from  'typescript' ; 
1212import  type  {  Compilation ,  Compiler ,  Module ,  NormalModule  }  from  'webpack' ; 
13- import  {  NgccProcessor  }  from  '../ngcc_processor' ; 
1413import  {  TypeScriptPathsPlugin  }  from  '../paths-plugin' ; 
1514import  {  WebpackResourceLoader  }  from  '../resource_loader' ; 
1615import  {  SourceFileCache  }  from  './cache' ; 
@@ -23,7 +22,6 @@ import {
2322import  { 
2423  augmentHostWithCaching , 
2524  augmentHostWithDependencyCollection , 
26-   augmentHostWithNgcc , 
2725  augmentHostWithReplacements , 
2826  augmentHostWithResources , 
2927  augmentHostWithSubstitutions , 
@@ -57,48 +55,11 @@ export interface AngularWebpackPluginOptions {
5755 * The Angular compilation state that is maintained across each Webpack compilation. 
5856 */ 
5957interface  AngularCompilationState  { 
60-   ngccProcessor ?: NgccProcessor ; 
6158  resourceLoader ?: WebpackResourceLoader ; 
6259  previousUnused ?: Set < string > ; 
6360  pathsPlugin : TypeScriptPathsPlugin ; 
6461} 
6562
66- function  initializeNgccProcessor ( 
67-   compiler : Compiler , 
68-   tsconfig : string , 
69-   compilerNgccModule : typeof  import ( '@angular/compiler-cli/ngcc' )  |  undefined , 
70- ) : {  processor : NgccProcessor ;  errors : string [ ] ;  warnings : string [ ]  }  { 
71-   const  {  inputFileSystem,  options : webpackOptions  }  =  compiler ; 
72-   const  mainFields  =  webpackOptions . resolve ?. mainFields ?. flat ( )  ??  [ ] ; 
73- 
74-   const  errors : string [ ]  =  [ ] ; 
75-   const  warnings : string [ ]  =  [ ] ; 
76-   const  resolver  =  compiler . resolverFactory . get ( 'normal' ,  { 
77-     // Caching must be disabled because it causes the resolver to become async after a rebuild 
78-     cache : false , 
79-     extensions : [ '.json' ] , 
80-     useSyncFileSystemCalls : true , 
81-   } ) ; 
82- 
83-   // The compilerNgccModule field is guaranteed to be defined during a compilation 
84-   // due to the `beforeCompile` hook. Usage of this property accessor prior to the 
85-   // hook execution is an implementation error. 
86-   assert . ok ( compilerNgccModule ,  `'@angular/compiler-cli/ngcc' used prior to Webpack compilation.` ) ; 
87- 
88-   const  processor  =  new  NgccProcessor ( 
89-     compilerNgccModule , 
90-     mainFields , 
91-     warnings , 
92-     errors , 
93-     compiler . context , 
94-     tsconfig , 
95-     inputFileSystem , 
96-     resolver , 
97-   ) ; 
98- 
99-   return  {  processor,  errors,  warnings } ; 
100- } 
101- 
10263const  PLUGIN_NAME  =  'angular-compiler' ; 
10364const  compilationFileEmitters  =  new  WeakMap < Compilation ,  FileEmitterCollection > ( ) ; 
10465
@@ -110,7 +71,6 @@ interface FileEmitHistoryItem {
11071export  class  AngularWebpackPlugin  { 
11172  private  readonly  pluginOptions : AngularWebpackPluginOptions ; 
11273  private  compilerCliModule ?: typeof  import ( '@angular/compiler-cli' ) ; 
113-   private  compilerNgccModule ?: typeof  import ( '@angular/compiler-cli/ngcc' ) ; 
11474  private  watchMode ?: boolean ; 
11575  private  ngtscNextProgram ?: NgtscProgram ; 
11676  private  builder ?: ts . EmitAndSemanticDiagnosticsBuilderProgram ; 
@@ -160,31 +120,10 @@ export class AngularWebpackPlugin {
160120      ) . apply ( compiler ) ; 
161121    } 
162122
163-     // Set resolver options 
164-     const  pathsPlugin  =  new  TypeScriptPathsPlugin ( ) ; 
165-     compiler . hooks . afterResolvers . tap ( PLUGIN_NAME ,  ( compiler )  =>  { 
166-       // When Ivy is enabled we need to add the fields added by NGCC 
167-       // to take precedence over the provided mainFields. 
168-       // NGCC adds fields in package.json suffixed with '_ivy_ngcc' 
169-       // Example: module -> module__ivy_ngcc 
170-       compiler . resolverFactory . hooks . resolveOptions 
171-         . for ( 'normal' ) 
172-         . tap ( PLUGIN_NAME ,  ( resolveOptions )  =>  { 
173-           const  originalMainFields  =  resolveOptions . mainFields ; 
174-           const  ivyMainFields  =  originalMainFields ?. flat ( ) . map ( ( f )  =>  `${ f }  _ivy_ngcc` )  ??  [ ] ; 
175- 
176-           resolveOptions . plugins  ??=  [ ] ; 
177-           resolveOptions . plugins . push ( pathsPlugin ) ; 
178- 
179-           // https://github.com/webpack/webpack/issues/11635#issuecomment-707016779 
180-           return  util . cleverMerge ( resolveOptions ,  {  mainFields : [ ...ivyMainFields ,  '...' ]  } ) ; 
181-         } ) ; 
182-     } ) ; 
183- 
184123    // Load the compiler-cli if not already available 
185124    compiler . hooks . beforeCompile . tapPromise ( PLUGIN_NAME ,  ( )  =>  this . initializeCompilerCli ( ) ) ; 
186125
187-     const  compilationState : AngularCompilationState  =  {  pathsPlugin } ; 
126+     const  compilationState : AngularCompilationState  =  {  pathsPlugin :  new   TypeScriptPathsPlugin ( )  } ; 
188127    compiler . hooks . thisCompilation . tap ( PLUGIN_NAME ,  ( compilation )  =>  { 
189128      try  { 
190129        this . setupCompilation ( compilation ,  compilationState ) ; 
@@ -216,21 +155,6 @@ export class AngularWebpackPlugin {
216155      state . resourceLoader  =  new  WebpackResourceLoader ( this . watchMode ) ; 
217156    } 
218157
219-     // Initialize and process eager ngcc if not already setup 
220-     if  ( ! state . ngccProcessor )  { 
221-       const  {  processor,  errors,  warnings }  =  initializeNgccProcessor ( 
222-         compiler , 
223-         this . pluginOptions . tsconfig , 
224-         this . compilerNgccModule , 
225-       ) ; 
226- 
227-       processor . process ( ) ; 
228-       warnings . forEach ( ( warning )  =>  addWarning ( compilation ,  warning ) ) ; 
229-       errors . forEach ( ( error )  =>  addError ( compilation ,  error ) ) ; 
230- 
231-       state . ngccProcessor  =  processor ; 
232-     } 
233- 
234158    // Setup and read TypeScript and Angular compiler configuration 
235159    const  {  compilerOptions,  rootNames,  errors }  =  this . loadConfiguration ( ) ; 
236160
@@ -284,9 +208,6 @@ export class AngularWebpackPlugin {
284208    // Setup source file dependency collection 
285209    augmentHostWithDependencyCollection ( host ,  this . fileDependencies ,  moduleResolutionCache ) ; 
286210
287-     // Setup on demand ngcc 
288-     augmentHostWithNgcc ( host ,  state . ngccProcessor ,  moduleResolutionCache ) ; 
289- 
290211    // Setup resource loading 
291212    state . resourceLoader . update ( compilation ,  changedFiles ) ; 
292213    augmentHostWithResources ( host ,  state . resourceLoader ,  { 
@@ -760,7 +681,6 @@ export class AngularWebpackPlugin {
760681    // Once TypeScript provides support for keeping the dynamic import this workaround can 
761682    // be dropped. 
762683    this . compilerCliModule  =  await  new  Function ( `return import('@angular/compiler-cli');` ) ( ) ; 
763-     this . compilerNgccModule  =  await  new  Function ( `return import('@angular/compiler-cli/ngcc');` ) ( ) ; 
764684  } 
765685
766686  private  async  addFileEmitHistory ( 
0 commit comments