5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- // tslint:disable
9
- // TODO: cleanup this file, it's copied as is from Angular CLI.
10
- import { CompilerOptions } from '@angular/compiler-cli' ;
11
8
import { buildOptimizerLoaderPath } from '@angular-devkit/build-optimizer' ;
12
9
import { 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' ;
23
13
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 ;
28
17
}
29
18
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
+ ) ;
38
25
39
- return true ;
26
+ wco . tsConfig . options . enableIvy = true ;
40
27
}
41
28
42
29
function createIvyPlugin (
@@ -73,111 +60,34 @@ function createIvyPlugin(
73
60
} ) ;
74
61
}
75
62
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
-
148
63
export function getNonAotConfig ( wco : WebpackConfigOptions ) {
149
64
const { tsConfigPath } = wco ;
150
- const useIvyOnlyPlugin = canUseIvyPlugin ( wco ) ;
151
65
152
66
return {
153
67
module : {
154
68
rules : [
155
69
{
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 ,
160
72
} ,
161
73
] ,
162
74
} ,
163
75
plugins : [
164
- useIvyOnlyPlugin
165
- ? createIvyPlugin ( wco , false , tsConfigPath )
166
- : _createAotPlugin ( wco , { tsConfigPath, skipCodeGeneration : true } ) ,
76
+ createIvyPlugin ( wco , false , tsConfigPath ) ,
167
77
] ,
168
78
} ;
169
79
}
170
80
171
- export function getAotConfig ( wco : WebpackConfigOptions , i18nExtract = false ) {
81
+ export function getAotConfig ( wco : WebpackConfigOptions ) {
172
82
const { tsConfigPath, buildOptions } = wco ;
173
- const optimize = buildOptions . optimization . scripts ;
174
- const useIvyOnlyPlugin = canUseIvyPlugin ( wco ) && ! i18nExtract ;
83
+
84
+ ensureIvy ( wco ) ;
175
85
176
86
return {
177
87
module : {
178
88
rules : [
179
89
{
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 ? $ / ,
181
91
use : [
182
92
...( buildOptions . buildOptimizer
183
93
? [
@@ -187,52 +97,22 @@ export function getAotConfig(wco: WebpackConfigOptions, i18nExtract = false) {
187
97
} ,
188
98
]
189
99
: [ ] ) ,
190
- useIvyOnlyPlugin ? ivy . AngularWebpackLoaderPath : NgToolsLoader ,
100
+ ivy . AngularWebpackLoaderPath ,
191
101
] ,
192
102
} ,
193
103
// "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
+ } ,
202
108
] ,
203
109
} ,
204
110
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 ) ,
212
112
] ,
213
113
} ;
214
114
}
215
115
216
116
export 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 ) ;
238
118
}
0 commit comments