Skip to content

Commit 84ec302

Browse files
clydinhansl
authored andcommitted
fix(@angular-devkit/build-angular): ensure failure with disabled AOT and enabled build optimizer
Fixes angular#11157
1 parent 232da54 commit 84ec302

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

packages/angular_devkit/build_angular/src/browser/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ export class BrowserBuilder implements Builder<BrowserBuilderSchema> {
7171
// Replace the assets in options with the normalized version.
7272
tap((assetPatternObjects => options.assets = assetPatternObjects)),
7373
concatMap(() => {
74-
// Ensure Build Optimizer is only used with AOT.
75-
if (options.buildOptimizer && !options.aot) {
76-
throw new Error('The `--build-optimizer` option cannot be used without `--aot`.');
77-
}
78-
7974
let webpackConfig;
8075
try {
8176
webpackConfig = this.buildWebpackConfig(root, projectRoot, host,
@@ -119,6 +114,11 @@ export class BrowserBuilder implements Builder<BrowserBuilderSchema> {
119114
host: virtualFs.Host<fs.Stats>,
120115
options: NormalizedBrowserBuilderSchema,
121116
) {
117+
// Ensure Build Optimizer is only used with AOT.
118+
if (options.buildOptimizer && !options.aot) {
119+
throw new Error('The `--build-optimizer` option cannot be used without `--aot`.');
120+
}
121+
122122
let wco: WebpackConfigOptions<NormalizedBrowserBuilderSchema>;
123123

124124
const tsConfigPath = getSystemPath(normalize(resolve(root, normalize(options.tsConfig))));

packages/angular_devkit/build_angular/test/browser/build-optimizer_spec_large.ts

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ describe('Browser Builder build optimizer', () => {
3030
).toPromise().then(done, done.fail);
3131
});
3232

33+
it('fails if AOT is disabled', (done) => {
34+
const overrides = { aot: false, buildOptimizer: true };
35+
runTargetSpec(host, browserTargetSpec, overrides)
36+
.toPromise().then(() => done.fail(), () => done());
37+
});
38+
3339
it('reduces bundle size', (done) => {
3440
const noBoOverrides = { aot: true, optimization: true, vendorChunk: false };
3541
const boOverrides = { ...noBoOverrides, buildOptimizer: true };

tests/legacy-cli/e2e/tests/build/build-optimizer.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export default function () {
1010
.then(() => expectToFail(() => expectFileToMatch('dist/test-project/main.js', /\.decorators =/)))
1111
.then(() => ng('build', '--prod'))
1212
.then(() => expectToFail(() => expectFileToExist('dist/vendor.js')))
13-
.then(() => expectToFail(() => expectFileToMatch('dist/test-project/main.js', /\.decorators =/)));
13+
.then(() => expectToFail(() => expectFileToMatch('dist/test-project/main.js', /\.decorators =/)))
14+
.then(() => expectToFail(() => ng('build', '--aot=false', '--build-optimizer')));
1415
}

0 commit comments

Comments
 (0)