@@ -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 ;
@@ -163,21 +123,13 @@ export class AngularWebpackPlugin {
163123 // Set resolver options
164124 const pathsPlugin = new TypeScriptPathsPlugin ( ) ;
165125 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
170126 compiler . resolverFactory . hooks . resolveOptions
171127 . for ( 'normal' )
172128 . tap ( PLUGIN_NAME , ( resolveOptions ) => {
173- const originalMainFields = resolveOptions . mainFields ;
174- const ivyMainFields = originalMainFields ?. flat ( ) . map ( ( f ) => `${ f } _ivy_ngcc` ) ?? [ ] ;
175-
176129 resolveOptions . plugins ??= [ ] ;
177130 resolveOptions . plugins . push ( pathsPlugin ) ;
178131
179- // https://github.com/webpack/webpack/issues/11635#issuecomment-707016779
180- return util . cleverMerge ( resolveOptions , { mainFields : [ ...ivyMainFields , '...' ] } ) ;
132+ return resolveOptions ;
181133 } ) ;
182134 } ) ;
183135
@@ -216,21 +168,6 @@ export class AngularWebpackPlugin {
216168 state . resourceLoader = new WebpackResourceLoader ( this . watchMode ) ;
217169 }
218170
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-
234171 // Setup and read TypeScript and Angular compiler configuration
235172 const { compilerOptions, rootNames, errors } = this . loadConfiguration ( ) ;
236173
@@ -284,9 +221,6 @@ export class AngularWebpackPlugin {
284221 // Setup source file dependency collection
285222 augmentHostWithDependencyCollection ( host , this . fileDependencies , moduleResolutionCache ) ;
286223
287- // Setup on demand ngcc
288- augmentHostWithNgcc ( host , state . ngccProcessor , moduleResolutionCache ) ;
289-
290224 // Setup resource loading
291225 state . resourceLoader . update ( compilation , changedFiles ) ;
292226 augmentHostWithResources ( host , state . resourceLoader , {
@@ -760,7 +694,6 @@ export class AngularWebpackPlugin {
760694 // Once TypeScript provides support for keeping the dynamic import this workaround can
761695 // be dropped.
762696 this . compilerCliModule = await new Function ( `return import('@angular/compiler-cli');` ) ( ) ;
763- this . compilerNgccModule = await new Function ( `return import('@angular/compiler-cli/ngcc');` ) ( ) ;
764697 }
765698
766699 private async addFileEmitHistory (
0 commit comments