Skip to content

Commit 451f17c

Browse files
authored
fix(@angular/cli): strip decorators with Angular 5+ (angular#8077)
We feel build `--build-optimizer` is stable enough to not be experimental anymore. This PR defaults `build-optimizer` when using Angular 5+ on a production build with `--aot`. It can still be turned off with `--no-build-optimizer` (or `--build-optimizer=false`). Fix angular#8050
1 parent 66f1898 commit 451f17c

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

docs/documentation/build.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Flag | `--dev` | `--prod`
8181
`--sourcemaps` | `true` | `false`
8282
`--extract-css` | `false` | `true`
8383
`--named-chunks`   | `true` | `false`
84+
`--build-optimizer` | `false` | `true` with AOT and Angular 5
8485

8586
`--extract-licenses` Extract all licenses in a separate file, in the case of production builds only.
8687
`--i18n-file` Localization file to use for i18n.
@@ -353,7 +354,7 @@ Note: service worker support is experimental and subject to change.
353354
<code>--build-optimizer</code>
354355
</p>
355356
<p>
356-
(Experimental) Enables @angular-devkit/build-optimizer optimizations when using `--aot`.
357+
Enables @angular-devkit/build-optimizer optimizations when using `--aot`.
357358
</p>
358359
</details>
359360

packages/@angular/cli/commands/build.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ export const baseBuildCommandOptions: any = [
166166
{
167167
name: 'build-optimizer',
168168
type: Boolean,
169-
default: false,
170-
description: '(Experimental) Enables @angular-devkit/build-optimizer '
171-
+ 'optimizations when using `--aot`.'
169+
description: 'Enables @angular-devkit/build-optimizer optimizations when using `--aot`.'
172170
},
173171
{
174172
name: 'named-chunks',

packages/@angular/cli/models/webpack-config.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AngularCompilerPlugin } from '@ngtools/webpack';
12
import { readTsconfig } from '../utilities/read-tsconfig';
23
const webpackMerge = require('webpack-merge');
34
import { CliConfig } from './config';
@@ -94,7 +95,8 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
9495
sourcemaps: true,
9596
extractCss: false,
9697
namedChunks: true,
97-
aot: false
98+
aot: false,
99+
buildOptimizer: false
98100
},
99101
production: {
100102
environment: 'prod',
@@ -106,7 +108,14 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
106108
}
107109
};
108110

109-
return Object.assign({}, targetDefaults[buildOptions.target], buildOptions);
111+
const merged = Object.assign({}, targetDefaults[buildOptions.target], buildOptions);
112+
113+
// Use Build Optimizer on prod AOT builds by default when AngularCompilerPlugin is supported.
114+
const buildOptimizer = {
115+
buildOptimizer: merged.aot && AngularCompilerPlugin.isSupported()
116+
};
117+
118+
return Object.assign({}, buildOptimizer, merged);
110119
}
111120

112121
// Fill in defaults from .angular-cli.json

tests/e2e/tests/build/aot/angular-compiler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ng, silentNpm } from '../../../utils/process';
22
import { updateJsonFile } from '../../../utils/project';
3-
import { expectFileToMatch, rimraf, moveFile } from '../../../utils/fs';
3+
import { expectFileToMatch, rimraf, moveFile, expectFileToExist } from '../../../utils/fs';
44
import { getGlobalVariable } from '../../../utils/env';
55
import { expectToFail } from '../../../utils/utils';
66

@@ -13,6 +13,7 @@ export default function () {
1313
return Promise.resolve();
1414
}
1515

16+
// These tests should be moved to the default when we use ng5 in new projects.
1617
return Promise.resolve()
1718
.then(() => moveFile('node_modules', '../node_modules'))
1819
.then(() => updateJsonFile('package.json', packageJson => {
@@ -36,6 +37,11 @@ export default function () {
3637
.then(() => expectFileToMatch('dist/main.bundle.js',
3738
/bootstrapModuleFactory.*\/\* AppModuleNgFactory \*\//))
3839

40+
// Build optimizer should default to true on prod builds.
41+
.then(() => ng('build', '--prod', '--output-hashing=none'))
42+
.then(() => expectToFail(() => expectFileToExist('dist/vendor.js')))
43+
.then(() => expectToFail(() => expectFileToMatch('dist/main.js', /\.decorators =/)))
44+
3945
// tests for register_locale_data transformer
4046
.then(() => rimraf('dist'))
4147
.then(() => ng('build', '--locale=fr'))

0 commit comments

Comments
 (0)