Skip to content

Commit 04a3607

Browse files
clydinfilipesilva
authored andcommitted
refactor(@angular/cli): simplify build option target defaults
1 parent d43bc61 commit 04a3607

File tree

2 files changed

+8
-34
lines changed

2 files changed

+8
-34
lines changed

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @ignoreDep typescript - used only for type information
22
import * as ts from 'typescript';
3-
import { AngularCompilerPlugin } from '@ngtools/webpack';
43
import { readTsconfig } from '../utilities/read-tsconfig';
54
import { requireProjectModule } from '../utilities/require-project-module';
65
const webpackMerge = require('webpack-merge');
@@ -93,7 +92,8 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
9392
extractCss: false,
9493
namedChunks: true,
9594
aot: false,
96-
buildOptimizer: false
95+
vendorChunk: true,
96+
buildOptimizer: false,
9797
},
9898
production: {
9999
environment: 'prod',
@@ -103,27 +103,12 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
103103
namedChunks: false,
104104
aot: true,
105105
extractLicenses: true,
106+
vendorChunk: false,
107+
buildOptimizer: buildOptions.aot !== false,
106108
}
107109
};
108110

109-
let merged = Object.assign({}, targetDefaults[buildOptions.target], buildOptions);
110-
111-
// Use Build Optimizer on prod AOT builds by default when AngularCompilerPlugin is supported.
112-
const buildOptimizerDefault = {
113-
buildOptimizer: buildOptions.target == 'production' && buildOptions.aot !== false
114-
&& AngularCompilerPlugin.isSupported()
115-
};
116-
117-
merged = Object.assign({}, buildOptimizerDefault, merged);
118-
119-
// Default vendor chunk to false when build optimizer is on.
120-
const vendorChunkDefault = {
121-
vendorChunk: !merged.buildOptimizer
122-
};
123-
124-
merged = Object.assign({}, vendorChunkDefault, merged);
125-
126-
return merged;
111+
return Object.assign({}, targetDefaults[buildOptions.target], buildOptions);
127112
}
128113

129114
// Fill in defaults from .angular-cli.json
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
import { ng } from '../../utils/process';
22
import { expectFileToMatch, expectFileToExist } from '../../utils/fs';
33
import { expectToFail } from '../../utils/utils';
4-
import { getGlobalVariable } from '../../utils/env';
54

65

76
export default function () {
87
return ng('build', '--aot', '--build-optimizer')
9-
.then(() => expectToFail(() => expectFileToExist('dist/vendor.js')))
108
.then(() => expectToFail(() => expectFileToMatch('dist/main.js', /\.decorators =/)))
11-
.then(() => {
12-
// Skip this part of the test in Angular 2/4.
13-
if (getGlobalVariable('argv').ng2 || getGlobalVariable('argv').ng4) {
14-
return Promise.resolve();
15-
}
16-
17-
// Check if build optimizer is on by default in ng5 prod builds
18-
return Promise.resolve()
19-
.then(() => ng('build', '--prod'))
20-
.then(() => expectToFail(() => expectFileToExist('dist/vendor.js')))
21-
.then(() => expectToFail(() => expectFileToMatch('dist/main.js', /\.decorators =/)));
22-
});
9+
.then(() => ng('build', '--prod'))
10+
.then(() => expectToFail(() => expectFileToExist('dist/vendor.js')))
11+
.then(() => expectToFail(() => expectFileToMatch('dist/main.js', /\.decorators =/)));
2312
}

0 commit comments

Comments
 (0)