Skip to content

fix(@angular-devkit/build-angular): ensure failure with disabled AOT and enabled build optimizer #11657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/angular_devkit/build_angular/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ export class BrowserBuilder implements Builder<BrowserBuilderSchema> {
// Replace the assets in options with the normalized version.
tap((assetPatternObjects => options.assets = assetPatternObjects)),
concatMap(() => {
// Ensure Build Optimizer is only used with AOT.
if (options.buildOptimizer && !options.aot) {
throw new Error('The `--build-optimizer` option cannot be used without `--aot`.');
}

let webpackConfig;
try {
webpackConfig = this.buildWebpackConfig(root, projectRoot, host,
Expand Down Expand Up @@ -119,6 +114,11 @@ export class BrowserBuilder implements Builder<BrowserBuilderSchema> {
host: virtualFs.Host<fs.Stats>,
options: NormalizedBrowserBuilderSchema,
) {
// Ensure Build Optimizer is only used with AOT.
if (options.buildOptimizer && !options.aot) {
throw new Error('The `--build-optimizer` option cannot be used without `--aot`.');
}

let wco: WebpackConfigOptions<NormalizedBrowserBuilderSchema>;

const tsConfigPath = getSystemPath(normalize(resolve(root, normalize(options.tsConfig))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ describe('Browser Builder build optimizer', () => {
).toPromise().then(done, done.fail);
});

it('fails if AOT is disabled', (done) => {
const overrides = { aot: false, buildOptimizer: true };
runTargetSpec(host, browserTargetSpec, overrides)
.toPromise().then(() => done.fail(), () => done());
});

it('reduces bundle size', (done) => {
const noBoOverrides = { aot: true, optimization: true, vendorChunk: false };
const boOverrides = { ...noBoOverrides, buildOptimizer: true };
Expand Down
3 changes: 2 additions & 1 deletion tests/legacy-cli/e2e/tests/build/build-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export default function () {
.then(() => expectToFail(() => expectFileToMatch('dist/test-project/main.js', /\.decorators =/)))
.then(() => ng('build', '--prod'))
.then(() => expectToFail(() => expectFileToExist('dist/vendor.js')))
.then(() => expectToFail(() => expectFileToMatch('dist/test-project/main.js', /\.decorators =/)));
.then(() => expectToFail(() => expectFileToMatch('dist/test-project/main.js', /\.decorators =/)))
.then(() => expectToFail(() => ng('build', '--aot=false', '--build-optimizer')));
}