Skip to content

Commit 0a74d0d

Browse files
alan-agius4josephperrott
authored andcommitted
fix(@angular-devkit/build-angular): change several builder options defaults
BREAKING CHANGE: A number of browser and server builder options have had their default values changed. The aim of these changes is to reduce the configuration complexity and support the new "production builds by default" initiative. **Browser builder** | Option | Previous default value | New default value | |----------------------------------------|---------------------------|-------------------| | optimization | false | true | | aot | false | true | | buildOptimizer | false | true | | sourceMap | true | false | | extractLicenses | false | true | | namedChunks | true | false | | vendorChunk | true | false | **Server builder** | Option | Previous default value | New default value | |---------------|------------------------|-------------------| | optimization | false | true | | sourceMap | true | false |
1 parent 49ba5e2 commit 0a74d0d

File tree

18 files changed

+160
-56
lines changed

18 files changed

+160
-56
lines changed

packages/angular_devkit/build_angular/src/browser/schema.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"optimization": {
7070
"description": "Enables optimization of the build output. Including minification of scripts and styles, tree-shaking, dead-code elimination, inlining of critical CSS and fonts inlining. For more information, see https://angular.io/guide/workspace-config#optimization-configuration.",
7171
"x-user-analytics": 16,
72-
"default": false,
72+
"default": true,
7373
"oneOf": [
7474
{
7575
"type": "object",
@@ -153,11 +153,11 @@
153153
"type": "boolean",
154154
"description": "Build using Ahead of Time compilation.",
155155
"x-user-analytics": 13,
156-
"default": false
156+
"default": true
157157
},
158158
"sourceMap": {
159159
"description": "Output source maps for scripts and styles. For more information, see https://angular.io/guide/workspace-config#source-map-configuration.",
160-
"default": true,
160+
"default": false,
161161
"oneOf": [
162162
{
163163
"type": "object",
@@ -193,7 +193,7 @@
193193
"vendorChunk": {
194194
"type": "boolean",
195195
"description": "Generate a seperate bundle containing only vendor libraries. This option should only used for development.",
196-
"default": true
196+
"default": false
197197
},
198198
"commonChunk": {
199199
"type": "boolean",
@@ -280,7 +280,7 @@
280280
"extractLicenses": {
281281
"type": "boolean",
282282
"description": "Extract all licenses in a separate file.",
283-
"default": false
283+
"default": true
284284
},
285285
"showCircularDependencies": {
286286
"type": "boolean",
@@ -291,12 +291,12 @@
291291
"buildOptimizer": {
292292
"type": "boolean",
293293
"description": "Enables '@angular-devkit/build-optimizer' optimizations when using the 'aot' option.",
294-
"default": false
294+
"default": true
295295
},
296296
"namedChunks": {
297297
"type": "boolean",
298298
"description": "Use file name for lazy loaded chunks.",
299-
"default": true
299+
"default": false
300300
},
301301
"subresourceIntegrity": {
302302
"type": "boolean",

packages/angular_devkit/build_angular/src/browser/specs/works_spec.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
2424
polyfills: 'src/polyfills.ts',
2525
tsConfig: 'src/tsconfig.app.json',
2626
progress: false,
27+
vendorChunk: true,
2728
assets: ['src/favicon.ico', 'src/assets'],
2829
styles: ['src/styles.css'],
2930
scripts: [],
@@ -33,13 +34,13 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
3334
await harness.executeOnce();
3435

3536
// Default files should be in outputPath.
36-
expect(harness.hasFile('dist/runtime.js')).toBe(true);
37-
expect(harness.hasFile('dist/main.js')).toBe(true);
38-
expect(harness.hasFile('dist/polyfills.js')).toBe(true);
39-
expect(harness.hasFile('dist/vendor.js')).toBe(true);
40-
expect(harness.hasFile('dist/favicon.ico')).toBe(true);
41-
expect(harness.hasFile('dist/styles.css')).toBe(true);
42-
expect(harness.hasFile('dist/index.html')).toBe(true);
37+
expect(harness.hasFile('dist/runtime.js')).toBeTrue();
38+
expect(harness.hasFile('dist/main.js')).toBeTrue();
39+
expect(harness.hasFile('dist/polyfills.js')).toBeTrue();
40+
expect(harness.hasFile('dist/vendor.js')).toBeTrue();
41+
expect(harness.hasFile('dist/favicon.ico')).toBeTrue();
42+
expect(harness.hasFile('dist/styles.css')).toBeTrue();
43+
expect(harness.hasFile('dist/index.html')).toBeTrue();
4344
});
4445
});
4546
});

packages/angular_devkit/build_angular/src/browser/tests/behavior/rebuild-errors_spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
281281
harness.useTarget('build', {
282282
...BASE_OPTIONS,
283283
watch: true,
284+
aot: false,
284285
});
285286

286287
const buildCount = await harness

packages/angular_devkit/build_angular/src/browser/tests/behavior/typescript-target_spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
3939

4040
harness.useTarget('build', {
4141
...BASE_OPTIONS,
42+
vendorChunk: true,
4243
});
4344

4445
const { result, logs } = await harness.executeOnce();
@@ -87,6 +88,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
8788

8889
harness.useTarget('build', {
8990
...BASE_OPTIONS,
91+
vendorChunk: true,
9092
sourceMap: {
9193
scripts: true,
9294
},
@@ -119,6 +121,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
119121

120122
harness.useTarget('build', {
121123
...BASE_OPTIONS,
124+
vendorChunk: true,
122125
});
123126

124127
const { result, logs } = await harness.executeOnce();

packages/angular_devkit/build_angular/src/browser/tests/options/extract-licenses_spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
3232
harness.expectFile('dist/3rdpartylicenses.txt').toNotExist();
3333
});
3434

35-
it(`should not generate '3rdpartylicenses.txt' when 'extractLicenses' is not set`, async () => {
35+
it(`should generate '3rdpartylicenses.txt' when 'extractLicenses' is not set`, async () => {
3636
harness.useTarget('build', {
3737
...BASE_OPTIONS,
3838
});
3939

4040
const { result } = await harness.executeOnce();
4141
expect(result?.success).toBe(true);
42-
harness.expectFile('dist/3rdpartylicenses.txt').toNotExist();
42+
harness.expectFile('dist/3rdpartylicenses.txt').content.toContain('MIT');
4343
});
4444
});
4545
});

packages/angular_devkit/build_angular/src/browser/tests/options/main_spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
2222

2323
harness.expectFile('dist/runtime.js').toExist();
2424
harness.expectFile('dist/main.js').toExist();
25-
harness.expectFile('dist/vendor.js').toExist();
2625
harness.expectFile('dist/index.html').toExist();
2726
});
2827

@@ -40,7 +39,6 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
4039

4140
harness.expectFile('dist/runtime.js').toExist();
4241
harness.expectFile('dist/main.js').toExist();
43-
harness.expectFile('dist/vendor.js').toNotExist();
4442
harness.expectFile('dist/index.html').toExist();
4543

4644
harness.expectFile('dist/main.js').content.toContain(`console.log('main')`);
@@ -61,7 +59,6 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
6159

6260
harness.expectFile('dist/runtime.js').toNotExist();
6361
harness.expectFile('dist/main.js').toNotExist();
64-
harness.expectFile('dist/vendor.js').toNotExist();
6562
harness.expectFile('dist/index.html').toNotExist();
6663
});
6764
});

packages/angular_devkit/build_angular/src/browser/tests/options/named-chunks_spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
6262
expect(result?.success).toBe(true);
6363

6464
harness.expectFile(MAIN_OUTPUT).toExist();
65-
harness.expectFile(NAMED_LAZY_OUTPUT).toExist();
66-
harness.expectFile(UNNAMED_LAZY_OUTPUT).toNotExist();
65+
harness.expectFile(NAMED_LAZY_OUTPUT).toNotExist();
66+
harness.expectFile(UNNAMED_LAZY_OUTPUT).toExist();
6767
});
6868
});
6969
});

packages/angular_devkit/build_angular/src/browser/tests/options/output-hashing_spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
1616
beforeEach(async () => {
1717
// Application code is not needed for asset tests
1818
await harness.writeFile('src/main.ts', '');
19+
await harness.writeFile('src/polyfills.ts', '');
1920
});
2021

2122
it('hashes all filenames when set to "all"', async () => {
@@ -27,6 +28,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
2728
harness.useTarget('build', {
2829
...BASE_OPTIONS,
2930
styles: ['src/styles.css'],
31+
polyfills: 'src/polyfills.ts',
3032
outputHashing: OutputHashing.All,
3133
});
3234

@@ -48,6 +50,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
4850

4951
harness.useTarget('build', {
5052
...BASE_OPTIONS,
53+
polyfills: 'src/polyfills.ts',
5154
styles: ['src/styles.css'],
5255
});
5356

@@ -70,6 +73,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
7073
harness.useTarget('build', {
7174
...BASE_OPTIONS,
7275
styles: ['src/styles.css'],
76+
polyfills: 'src/polyfills.ts',
7377
outputHashing: OutputHashing.None,
7478
});
7579

@@ -92,6 +96,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
9296
harness.useTarget('build', {
9397
...BASE_OPTIONS,
9498
styles: ['src/styles.css'],
99+
polyfills: 'src/polyfills.ts',
95100
outputHashing: OutputHashing.Media,
96101
});
97102

@@ -114,6 +119,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
114119
harness.useTarget('build', {
115120
...BASE_OPTIONS,
116121
styles: ['src/styles.css'],
122+
polyfills: 'src/polyfills.ts',
117123
outputHashing: OutputHashing.Bundles,
118124
});
119125

@@ -131,6 +137,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
131137
harness.useTarget('build', {
132138
...BASE_OPTIONS,
133139
outputHashing: OutputHashing.All,
140+
sourceMap: true,
134141
styles: [{
135142
input: 'src/styles.css',
136143
inject: false,

packages/angular_devkit/build_angular/src/browser/tests/setup.ts

+4
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ export const BASE_OPTIONS = Object.freeze<Schema>({
2424
outputPath: 'dist',
2525
tsConfig: 'src/tsconfig.app.json',
2626
progress: false,
27+
28+
// Disable optimizations
29+
optimization: false,
30+
buildOptimizer: false,
2731
});

packages/angular_devkit/build_angular/src/dev-server/tests/setup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const DEV_SERVER_BUILDER_INFO = Object.freeze({
2424
});
2525

2626
/**
27-
* Contains all required extract-i18n builder fields.
27+
* Contains all required dev-server builder fields.
2828
* The port is also set to zero to ensure a free port is used for each test which
2929
* supports parallel test execution.
3030
*/

packages/angular_devkit/build_angular/src/extract-i18n/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { Diagnostics } from '@angular/localize/src/tools/src/diagnostics';
1717
import * as fs from 'fs';
1818
import * as path from 'path';
1919
import * as webpack from 'webpack';
20-
import { Schema as BrowserBuilderOptions } from '../browser/schema';
20+
import { OutputHashing, Schema as BrowserBuilderOptions } from '../browser/schema';
2121
import { ExecutionTransformer } from '../transforms';
2222
import { createI18nOptions } from '../utils/i18n-options';
2323
import { assertCompatibleAngularVersion } from '../utils/version';
@@ -177,12 +177,15 @@ export async function execute(
177177
buildOptimizer: false,
178178
aot: true,
179179
progress: options.progress,
180+
budgets: [],
180181
assets: [],
181182
scripts: [],
182183
styles: [],
183184
deleteOutputPath: false,
184185
extractLicenses: false,
185186
subresourceIntegrity: false,
187+
outputHashing: OutputHashing.None,
188+
namedChunks: true,
186189
},
187190
context,
188191
(wco) => {

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { dirname, resolve } from 'path';
1212
import { Observable, from } from 'rxjs';
1313
import { defaultIfEmpty, switchMap } from 'rxjs/operators';
1414
import * as webpack from 'webpack';
15-
import { Schema as BrowserBuilderOptions } from '../browser/schema';
15+
import { OutputHashing, Schema as BrowserBuilderOptions } from '../browser/schema';
1616
import { ExecutionTransformer } from '../transforms';
1717
import { assertCompatibleAngularVersion } from '../utils/version';
1818
import { generateBrowserWebpackConfigFromContext } from '../utils/webpack-browser-config';
@@ -41,7 +41,18 @@ async function initialize(
4141
// only two properties are missing:
4242
// * `outputPath` which is fixed for tests
4343
// * `budgets` which might be incorrect due to extra dev libs
44-
{ ...((options as unknown) as BrowserBuilderOptions), outputPath: '', budgets: undefined },
44+
{
45+
...((options as unknown) as BrowserBuilderOptions),
46+
outputPath: '',
47+
budgets: undefined,
48+
optimization: false,
49+
buildOptimizer: false,
50+
aot: false,
51+
vendorChunk: true,
52+
namedChunks: true,
53+
extractLicenses: false,
54+
outputHashing: OutputHashing.None,
55+
},
4556
context,
4657
wco => [
4758
getCommonConfig(wco),

packages/angular_devkit/build_angular/src/server/schema.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"optimization": {
4343
"description": "Enables optimization of the build output. Including minification of scripts and styles, tree-shaking and dead-code elimination. For more information, see https://angular.io/guide/workspace-config#optimization-configuration.",
4444
"x-user-analytics": 16,
45-
"default": false,
45+
"default": true,
4646
"oneOf": [
4747
{
4848
"type": "object",
@@ -84,7 +84,7 @@
8484
},
8585
"sourceMap": {
8686
"description": "Output source maps for scripts and styles. For more information, see https://angular.io/guide/workspace-config#source-map-configuration.",
87-
"default": true,
87+
"default": false,
8888
"oneOf": [
8989
{
9090
"type": "object",
@@ -189,7 +189,7 @@
189189
"namedChunks": {
190190
"type": "boolean",
191191
"description": "Use file name for lazy loaded chunks.",
192-
"default": true
192+
"default": false
193193
},
194194
"bundleDependencies": {
195195
"description": "Which external dependencies to bundle into the bundle. By default, all of node_modules will be bundled.",

packages/angular_devkit/build_angular/src/utils/normalize-optimization.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type NormalizedOptimizationOptions = Required<Omit<OptimizationClass, 'fo
1313
styles: StylesClass,
1414
};
1515

16-
export function normalizeOptimization(optimization: OptimizationUnion = false): NormalizedOptimizationOptions {
16+
export function normalizeOptimization(optimization: OptimizationUnion = true): NormalizedOptimizationOptions {
1717
if (typeof optimization === 'object') {
1818
return {
1919
scripts: !!optimization.scripts,

packages/angular_devkit/build_angular/test/hello-world-app/angular.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
"polyfills": "src/polyfills.ts",
2323
"tsConfig": "src/tsconfig.app.json",
2424
"progress": false,
25+
"sourceMap": true,
26+
"aot": false,
27+
"vendorChunk": true,
28+
"buildOptimizer": false,
29+
"optimization": false,
30+
"extractLicenses": false,
31+
"namedChunks": true,
2532
"assets": [
2633
"src/favicon.ico",
2734
"src/assets"
@@ -67,7 +74,10 @@
6774
"outputPath": "dist-server",
6875
"main": "src/main.server.ts",
6976
"tsConfig": "src/tsconfig.server.json",
70-
"progress": false
77+
"progress": false,
78+
"sourceMap": true,
79+
"optimization": false,
80+
"extractLicenses": false
7181
}
7282
},
7383
"app-shell": {

packages/schematics/angular/application/index.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
160160
main: `${sourceRoot}/main.ts`,
161161
polyfills: `${sourceRoot}/polyfills.ts`,
162162
tsConfig: `${projectRoot}tsconfig.app.json`,
163-
aot: true,
164163
inlineStyleLanguage,
165164
assets: [
166165
`${sourceRoot}/favicon.ico`,
@@ -178,16 +177,15 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
178177
replace: `${sourceRoot}/environments/environment.ts`,
179178
with: `${sourceRoot}/environments/environment.prod.ts`,
180179
}],
181-
buildOptimizer: true,
182-
optimization: true,
183180
outputHashing: 'all',
184-
sourceMap: false,
185-
namedChunks: false,
186-
extractLicenses: true,
187-
vendorChunk: false,
188181
},
189182
development: {
183+
buildOptimizer: false,
184+
optimization: false,
190185
vendorChunk: true,
186+
extractLicenses: false,
187+
sourceMap: true,
188+
namedChunks: true,
191189
},
192190
},
193191
},

0 commit comments

Comments
 (0)