Skip to content

Commit

Permalink
fix(@angular/cli): strip decorators with Angular 5+ (#8077)
Browse files Browse the repository at this point in the history
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 #8050
  • Loading branch information
filipesilva committed Oct 18, 2017
1 parent c410ba9 commit d860591
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion docs/documentation/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Flag | `--dev` | `--prod`
`--sourcemaps` | `true` | `false`
`--extract-css` | `false` | `true`
`--named-chunks`   | `true` | `false`
`--build-optimizer` | `false` | `true` with AOT and Angular 5

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

Expand Down
4 changes: 1 addition & 3 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ export const baseBuildCommandOptions: any = [
{
name: 'build-optimizer',
type: Boolean,
default: false,
description: '(Experimental) Enables @angular-devkit/build-optimizer '
+ 'optimizations when using `--aot`.'
description: 'Enables @angular-devkit/build-optimizer optimizations when using `--aot`.'
},
{
name: 'named-chunks',
Expand Down
13 changes: 11 additions & 2 deletions packages/@angular/cli/models/webpack-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AngularCompilerPlugin } from '@ngtools/webpack';
import { readTsconfig } from '../utilities/read-tsconfig';
const webpackMerge = require('webpack-merge');
import { CliConfig } from './config';
Expand Down Expand Up @@ -94,7 +95,8 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
sourcemaps: true,
extractCss: false,
namedChunks: true,
aot: false
aot: false,
buildOptimizer: false
},
production: {
environment: 'prod',
Expand All @@ -106,7 +108,14 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
}
};

return Object.assign({}, targetDefaults[buildOptions.target], buildOptions);
const merged = Object.assign({}, targetDefaults[buildOptions.target], buildOptions);

// Use Build Optimizer on prod AOT builds by default when AngularCompilerPlugin is supported.
const buildOptimizer = {
buildOptimizer: merged.aot && AngularCompilerPlugin.isSupported()
};

return Object.assign({}, buildOptimizer, merged);
}

// Fill in defaults from .angular-cli.json
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e/tests/build/aot/angular-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ng, silentNpm } from '../../../utils/process';
import { updateJsonFile } from '../../../utils/project';
import { expectFileToMatch, rimraf, moveFile } from '../../../utils/fs';
import { expectFileToMatch, rimraf, moveFile, expectFileToExist } from '../../../utils/fs';
import { getGlobalVariable } from '../../../utils/env';
import { expectToFail } from '../../../utils/utils';

Expand All @@ -13,6 +13,7 @@ export default function () {
return Promise.resolve();
}

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

// Build optimizer should default to true on prod builds.
.then(() => ng('build', '--prod', '--output-hashing=none'))
.then(() => expectToFail(() => expectFileToExist('dist/vendor.js')))
.then(() => expectToFail(() => expectFileToMatch('dist/main.js', /\.decorators =/)))

// tests for register_locale_data transformer
.then(() => rimraf('dist'))
.then(() => ng('build', '--locale=fr'))
Expand Down

0 comments on commit d860591

Please sign in to comment.