55 * Use of this source code is governed by an MIT-style license that can be
66 * found in the LICENSE file at https://angular.io/license
77 */
8- // tslint:disable
9- // TODO: cleanup this file, it's copied as is from Angular CLI.
10- import { CompilerOptions } from '@angular/compiler-cli' ;
118import { buildOptimizerLoaderPath } from '@angular-devkit/build-optimizer' ;
129import { getSystemPath } from '@angular-devkit/core' ;
13- import {
14- AngularCompilerPlugin ,
15- AngularCompilerPluginOptions ,
16- NgToolsLoader ,
17- PLATFORM ,
18- ivy ,
19- } from '@ngtools/webpack' ;
20- import * as path from 'path' ;
21- import { WebpackConfigOptions , BuildOptions } from '../../utils/build-options' ;
22- import { legacyIvyPluginEnabled } from '../../utils/environment-options' ;
10+ import { CompilerOptions } from '@angular/compiler-cli' ;
11+ import { ivy } from '@ngtools/webpack' ;
12+ import { WebpackConfigOptions } from '../../utils/build-options' ;
2313
24- function canUseIvyPlugin ( wco : WebpackConfigOptions ) : boolean {
25- // Can only be used with Ivy
26- if ( ! wco . tsConfig . options . enableIvy ) {
27- return false ;
14+ function ensureIvy ( wco : WebpackConfigOptions ) : void {
15+ if ( wco . tsConfig . options . enableIvy !== false ) {
16+ return ;
2817 }
2918
30- // Allow fallback to legacy build system via environment variable ('NG_BUILD_IVY_LEGACY=1')
31- if ( legacyIvyPluginEnabled ) {
32- wco . logger . warn (
33- '"NG_BUILD_IVY_LEGACY" environment variable detected. Using legacy Ivy build system.' ,
34- ) ;
35-
36- return false ;
37- }
19+ wco . logger . warn (
20+ 'Project is attempting to disable the Ivy compiler. ' +
21+ 'Angular versions 12 and higher do not support the deprecated View Engine compiler for applications. ' +
22+ 'The Ivy compiler will be used to build this project. ' +
23+ '\nFor additional information or if the build fails, please see https://angular.io/guide/ivy' ,
24+ ) ;
3825
39- return true ;
26+ wco . tsConfig . options . enableIvy = true ;
4027}
4128
4229function createIvyPlugin (
@@ -73,111 +60,34 @@ function createIvyPlugin(
7360 } ) ;
7461}
7562
76- function _pluginOptionsOverrides (
77- buildOptions : BuildOptions ,
78- pluginOptions : AngularCompilerPluginOptions
79- ) : AngularCompilerPluginOptions {
80- const compilerOptions = {
81- ...( pluginOptions . compilerOptions || { } )
82- }
83-
84- const hostReplacementPaths : { [ replace : string ] : string } = { } ;
85- if ( buildOptions . fileReplacements ) {
86- for ( const replacement of buildOptions . fileReplacements ) {
87- hostReplacementPaths [ replacement . replace ] = replacement . with ;
88- }
89- }
90-
91- if ( buildOptions . preserveSymlinks ) {
92- compilerOptions . preserveSymlinks = true ;
93- }
94-
95- return {
96- ...pluginOptions ,
97- hostReplacementPaths,
98- compilerOptions
99- } ;
100- }
101-
102- function _createAotPlugin (
103- wco : WebpackConfigOptions ,
104- options : AngularCompilerPluginOptions ,
105- i18nExtract = false ,
106- ) {
107- const { root, buildOptions } = wco ;
108-
109- const i18nInFile = buildOptions . i18nFile
110- ? path . resolve ( root , buildOptions . i18nFile )
111- : undefined ;
112-
113- const i18nFileAndFormat = i18nExtract
114- ? {
115- i18nOutFile : buildOptions . i18nFile ,
116- i18nOutFormat : buildOptions . i18nFormat ,
117- } : {
118- i18nInFile : i18nInFile ,
119- i18nInFormat : buildOptions . i18nFormat ,
120- } ;
121-
122- const compilerOptions = options . compilerOptions || { } ;
123- if ( i18nExtract ) {
124- // Extraction of i18n is still using the legacy VE pipeline
125- compilerOptions . enableIvy = false ;
126- }
127-
128- let pluginOptions : AngularCompilerPluginOptions = {
129- mainPath : path . join ( root , buildOptions . main ) ,
130- ...i18nFileAndFormat ,
131- locale : buildOptions . i18nLocale ,
132- platform : buildOptions . platform === 'server' ? PLATFORM . Server : PLATFORM . Browser ,
133- missingTranslation : buildOptions . i18nMissingTranslation ,
134- sourceMap : buildOptions . sourceMap . scripts ,
135- nameLazyFiles : buildOptions . namedChunks ,
136- forkTypeChecker : buildOptions . forkTypeChecker ,
137- logger : wco . logger ,
138- directTemplateLoading : true ,
139- ...options ,
140- compilerOptions,
141- } ;
142-
143- pluginOptions = _pluginOptionsOverrides ( buildOptions , pluginOptions ) ;
144-
145- return new AngularCompilerPlugin ( pluginOptions ) ;
146- }
147-
14863export function getNonAotConfig ( wco : WebpackConfigOptions ) {
14964 const { tsConfigPath } = wco ;
150- const useIvyOnlyPlugin = canUseIvyPlugin ( wco ) ;
15165
15266 return {
15367 module : {
15468 rules : [
15569 {
156- test : useIvyOnlyPlugin ? / \. [ j t ] s x ? $ / : / \. t s x ? $ / ,
157- loader : useIvyOnlyPlugin
158- ? ivy . AngularWebpackLoaderPath
159- : NgToolsLoader ,
70+ test : / \. [ j t ] s x ? $ / ,
71+ loader : ivy . AngularWebpackLoaderPath ,
16072 } ,
16173 ] ,
16274 } ,
16375 plugins : [
164- useIvyOnlyPlugin
165- ? createIvyPlugin ( wco , false , tsConfigPath )
166- : _createAotPlugin ( wco , { tsConfigPath, skipCodeGeneration : true } ) ,
76+ createIvyPlugin ( wco , false , tsConfigPath ) ,
16777 ] ,
16878 } ;
16979}
17080
171- export function getAotConfig ( wco : WebpackConfigOptions , i18nExtract = false ) {
81+ export function getAotConfig ( wco : WebpackConfigOptions ) {
17282 const { tsConfigPath, buildOptions } = wco ;
173- const optimize = buildOptions . optimization . scripts ;
174- const useIvyOnlyPlugin = canUseIvyPlugin ( wco ) && ! i18nExtract ;
83+
84+ ensureIvy ( wco ) ;
17585
17686 return {
17787 module : {
17888 rules : [
17989 {
180- test : useIvyOnlyPlugin ? / \. t s x ? $ / : / (?: \. n g f a c t o r y \. j s | \. n g s t y l e \. j s | \. t s x ? ) $ / ,
90+ test : / \. t s x ? $ / ,
18191 use : [
18292 ...( buildOptions . buildOptimizer
18393 ? [
@@ -187,52 +97,22 @@ export function getAotConfig(wco: WebpackConfigOptions, i18nExtract = false) {
18797 } ,
18898 ]
18999 : [ ] ) ,
190- useIvyOnlyPlugin ? ivy . AngularWebpackLoaderPath : NgToolsLoader ,
100+ ivy . AngularWebpackLoaderPath ,
191101 ] ,
192102 } ,
193103 // "allowJs" support with ivy plugin - ensures build optimizer is not run twice
194- ...( useIvyOnlyPlugin
195- ? [
196- {
197- test : / \. j s x ? $ / ,
198- use : [ ivy . AngularWebpackLoaderPath ] ,
199- } ,
200- ]
201- : [ ] ) ,
104+ {
105+ test : / \. j s x ? $ / ,
106+ use : [ ivy . AngularWebpackLoaderPath ] ,
107+ } ,
202108 ] ,
203109 } ,
204110 plugins : [
205- useIvyOnlyPlugin
206- ? createIvyPlugin ( wco , true , tsConfigPath )
207- : _createAotPlugin (
208- wco ,
209- { tsConfigPath, emitClassMetadata : ! optimize , emitNgModuleScope : ! optimize } ,
210- i18nExtract ,
211- ) ,
111+ createIvyPlugin ( wco , true , tsConfigPath ) ,
212112 ] ,
213113 } ;
214114}
215115
216116export function getTypescriptWorkerPlugin ( wco : WebpackConfigOptions , workerTsConfigPath : string ) {
217- if ( canUseIvyPlugin ( wco ) ) {
218- return createIvyPlugin ( wco , false , workerTsConfigPath ) ;
219- }
220-
221- const { buildOptions } = wco ;
222-
223- let pluginOptions : AngularCompilerPluginOptions = {
224- skipCodeGeneration : true ,
225- tsConfigPath : workerTsConfigPath ,
226- mainPath : undefined ,
227- platform : PLATFORM . Browser ,
228- sourceMap : buildOptions . sourceMap . scripts ,
229- forkTypeChecker : buildOptions . forkTypeChecker ,
230- logger : wco . logger ,
231- // Run no transformers.
232- platformTransformers : [ ] ,
233- } ;
234-
235- pluginOptions = _pluginOptionsOverrides ( buildOptions , pluginOptions ) ;
236-
237- return new AngularCompilerPlugin ( pluginOptions ) ;
117+ return createIvyPlugin ( wco , false , workerTsConfigPath ) ;
238118}
0 commit comments