mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-28 02:58:04 +08:00
refactor(@angular/cli): simplify build option target defaults
This commit is contained in:
parent
d43bc61fa1
commit
04a36075e2
@ -1,6 +1,5 @@
|
||||
// @ignoreDep typescript - used only for type information
|
||||
import * as ts from 'typescript';
|
||||
import { AngularCompilerPlugin } from '@ngtools/webpack';
|
||||
import { readTsconfig } from '../utilities/read-tsconfig';
|
||||
import { requireProjectModule } from '../utilities/require-project-module';
|
||||
const webpackMerge = require('webpack-merge');
|
||||
@ -93,7 +92,8 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
|
||||
extractCss: false,
|
||||
namedChunks: true,
|
||||
aot: false,
|
||||
buildOptimizer: false
|
||||
vendorChunk: true,
|
||||
buildOptimizer: false,
|
||||
},
|
||||
production: {
|
||||
environment: 'prod',
|
||||
@ -103,27 +103,12 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
|
||||
namedChunks: false,
|
||||
aot: true,
|
||||
extractLicenses: true,
|
||||
vendorChunk: false,
|
||||
buildOptimizer: buildOptions.aot !== false,
|
||||
}
|
||||
};
|
||||
|
||||
let merged = Object.assign({}, targetDefaults[buildOptions.target], buildOptions);
|
||||
|
||||
// Use Build Optimizer on prod AOT builds by default when AngularCompilerPlugin is supported.
|
||||
const buildOptimizerDefault = {
|
||||
buildOptimizer: buildOptions.target == 'production' && buildOptions.aot !== false
|
||||
&& AngularCompilerPlugin.isSupported()
|
||||
};
|
||||
|
||||
merged = Object.assign({}, buildOptimizerDefault, merged);
|
||||
|
||||
// Default vendor chunk to false when build optimizer is on.
|
||||
const vendorChunkDefault = {
|
||||
vendorChunk: !merged.buildOptimizer
|
||||
};
|
||||
|
||||
merged = Object.assign({}, vendorChunkDefault, merged);
|
||||
|
||||
return merged;
|
||||
return Object.assign({}, targetDefaults[buildOptions.target], buildOptions);
|
||||
}
|
||||
|
||||
// Fill in defaults from .angular-cli.json
|
||||
|
@ -1,23 +1,12 @@
|
||||
import { ng } from '../../utils/process';
|
||||
import { expectFileToMatch, expectFileToExist } from '../../utils/fs';
|
||||
import { expectToFail } from '../../utils/utils';
|
||||
import { getGlobalVariable } from '../../utils/env';
|
||||
|
||||
|
||||
export default function () {
|
||||
return ng('build', '--aot', '--build-optimizer')
|
||||
.then(() => expectToFail(() => expectFileToExist('dist/vendor.js')))
|
||||
.then(() => expectToFail(() => expectFileToMatch('dist/main.js', /\.decorators =/)))
|
||||
.then(() => {
|
||||
// Skip this part of the test in Angular 2/4.
|
||||
if (getGlobalVariable('argv').ng2 || getGlobalVariable('argv').ng4) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// Check if build optimizer is on by default in ng5 prod builds
|
||||
return Promise.resolve()
|
||||
.then(() => ng('build', '--prod'))
|
||||
.then(() => expectToFail(() => expectFileToExist('dist/vendor.js')))
|
||||
.then(() => expectToFail(() => expectFileToMatch('dist/main.js', /\.decorators =/)));
|
||||
});
|
||||
.then(() => ng('build', '--prod'))
|
||||
.then(() => expectToFail(() => expectFileToExist('dist/vendor.js')))
|
||||
.then(() => expectToFail(() => expectFileToMatch('dist/main.js', /\.decorators =/)));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user