Skip to content

Commit 677913f

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): remove usage of deprecated View Engine compiler
BREAKING CHANGE: Removal of View Engine support from application builds With the removal of the deprecated View Engine compiler in Angular version 12 for applications, Ivy-based compilation will always be used when building an application. The default behavior for applications is to use the Ivy compiler when building and no changes are required for these applications. For applications that have opted-out of Ivy, a warning will be shown and an Ivy-based build will be attempted. If the build fails, the application may need to be updated to become Ivy compatible.
1 parent f6759c0 commit 677913f

File tree

3 files changed

+28
-153
lines changed

3 files changed

+28
-153
lines changed

packages/angular_devkit/build_angular/src/utils/environment-options.ts

-5
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,3 @@ export const cachingBasePath = (() => {
8282
// Build profiling
8383
const profilingVariable = process.env['NG_BUILD_PROFILING'];
8484
export const profilingEnabled = isPresent(profilingVariable) && isEnabled(profilingVariable);
85-
86-
// Legacy Webpack plugin with Ivy
87-
const legacyIvyVariable = process.env['NG_BUILD_IVY_LEGACY'];
88-
export const legacyIvyPluginEnabled =
89-
isPresent(legacyIvyVariable) && !isDisabled(legacyIvyVariable);

packages/angular_devkit/build_angular/src/webpack/configs/typescript.ts

+27-147
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,25 @@
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';
118
import { buildOptimizerLoaderPath } from '@angular-devkit/build-optimizer';
129
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';
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

4229
function 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-
14863
export function getNonAotConfig(wco: WebpackConfigOptions) {
14964
const { tsConfigPath } = wco;
150-
const useIvyOnlyPlugin = canUseIvyPlugin(wco);
15165

15266
return {
15367
module: {
15468
rules: [
15569
{
156-
test: useIvyOnlyPlugin ? /\.[jt]sx?$/ : /\.tsx?$/,
157-
loader: useIvyOnlyPlugin
158-
? ivy.AngularWebpackLoaderPath
159-
: NgToolsLoader,
70+
test: /\.[jt]sx?$/,
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 ? /\.tsx?$/ : /(?:\.ngfactory\.js|\.ngstyle\.js|\.tsx?)$/,
90+
test: /\.tsx?$/,
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: /\.jsx?$/,
198-
use: [ivy.AngularWebpackLoaderPath],
199-
},
200-
]
201-
: []),
104+
{
105+
test: /\.jsx?$/,
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

216116
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);
238118
}

tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default async function() {
4242
});
4343

4444
// Should show ivy disabled application warning with enableIvy false
45-
const { message: message4 } = await expectToFail(() => ng('extract-i18n'));
45+
const { stderr: message4 } = await ng('extract-i18n');
4646
if (!message4.includes(`Ivy extraction enabled but application is not Ivy enabled.`)) {
4747
throw new Error('Expected ivy disabled application warning');
4848
}

0 commit comments

Comments
 (0)