Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): change several builder options de…
Browse files Browse the repository at this point in the history
…faults

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             |

(cherry picked from commit 0a74d0d)
  • Loading branch information
alan-agius4 authored and josephperrott committed Apr 21, 2021
1 parent 5197f42 commit 656f8d7
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 56 deletions.
14 changes: 7 additions & 7 deletions packages/angular_devkit/build_angular/src/browser/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"optimization": {
"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.",
"x-user-analytics": 16,
"default": false,
"default": true,
"oneOf": [
{
"type": "object",
Expand Down Expand Up @@ -153,11 +153,11 @@
"type": "boolean",
"description": "Build using Ahead of Time compilation.",
"x-user-analytics": 13,
"default": false
"default": true
},
"sourceMap": {
"description": "Output source maps for scripts and styles. For more information, see https://angular.io/guide/workspace-config#source-map-configuration.",
"default": true,
"default": false,
"oneOf": [
{
"type": "object",
Expand Down Expand Up @@ -193,7 +193,7 @@
"vendorChunk": {
"type": "boolean",
"description": "Generate a seperate bundle containing only vendor libraries. This option should only used for development.",
"default": true
"default": false
},
"commonChunk": {
"type": "boolean",
Expand Down Expand Up @@ -280,7 +280,7 @@
"extractLicenses": {
"type": "boolean",
"description": "Extract all licenses in a separate file.",
"default": false
"default": true
},
"showCircularDependencies": {
"type": "boolean",
Expand All @@ -291,12 +291,12 @@
"buildOptimizer": {
"type": "boolean",
"description": "Enables '@angular-devkit/build-optimizer' optimizations when using the 'aot' option.",
"default": false
"default": true
},
"namedChunks": {
"type": "boolean",
"description": "Use file name for lazy loaded chunks.",
"default": true
"default": false
},
"subresourceIntegrity": {
"type": "boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
polyfills: 'src/polyfills.ts',
tsConfig: 'src/tsconfig.app.json',
progress: false,
vendorChunk: true,
assets: ['src/favicon.ico', 'src/assets'],
styles: ['src/styles.css'],
scripts: [],
Expand All @@ -33,13 +34,13 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
await harness.executeOnce();

// Default files should be in outputPath.
expect(harness.hasFile('dist/runtime.js')).toBe(true);
expect(harness.hasFile('dist/main.js')).toBe(true);
expect(harness.hasFile('dist/polyfills.js')).toBe(true);
expect(harness.hasFile('dist/vendor.js')).toBe(true);
expect(harness.hasFile('dist/favicon.ico')).toBe(true);
expect(harness.hasFile('dist/styles.css')).toBe(true);
expect(harness.hasFile('dist/index.html')).toBe(true);
expect(harness.hasFile('dist/runtime.js')).toBeTrue();
expect(harness.hasFile('dist/main.js')).toBeTrue();
expect(harness.hasFile('dist/polyfills.js')).toBeTrue();
expect(harness.hasFile('dist/vendor.js')).toBeTrue();
expect(harness.hasFile('dist/favicon.ico')).toBeTrue();
expect(harness.hasFile('dist/styles.css')).toBeTrue();
expect(harness.hasFile('dist/index.html')).toBeTrue();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
harness.useTarget('build', {
...BASE_OPTIONS,
watch: true,
aot: false,
});

const buildCount = await harness
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {

harness.useTarget('build', {
...BASE_OPTIONS,
vendorChunk: true,
});

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

harness.useTarget('build', {
...BASE_OPTIONS,
vendorChunk: true,
sourceMap: {
scripts: true,
},
Expand Down Expand Up @@ -119,6 +121,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {

harness.useTarget('build', {
...BASE_OPTIONS,
vendorChunk: true,
});

const { result, logs } = await harness.executeOnce();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
harness.expectFile('dist/3rdpartylicenses.txt').toNotExist();
});

it(`should not generate '3rdpartylicenses.txt' when 'extractLicenses' is not set`, async () => {
it(`should generate '3rdpartylicenses.txt' when 'extractLicenses' is not set`, async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
});

const { result } = await harness.executeOnce();
expect(result?.success).toBe(true);
harness.expectFile('dist/3rdpartylicenses.txt').toNotExist();
harness.expectFile('dist/3rdpartylicenses.txt').content.toContain('MIT');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {

harness.expectFile('dist/runtime.js').toExist();
harness.expectFile('dist/main.js').toExist();
harness.expectFile('dist/vendor.js').toExist();
harness.expectFile('dist/index.html').toExist();
});

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

harness.expectFile('dist/runtime.js').toExist();
harness.expectFile('dist/main.js').toExist();
harness.expectFile('dist/vendor.js').toNotExist();
harness.expectFile('dist/index.html').toExist();

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

harness.expectFile('dist/runtime.js').toNotExist();
harness.expectFile('dist/main.js').toNotExist();
harness.expectFile('dist/vendor.js').toNotExist();
harness.expectFile('dist/index.html').toNotExist();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
expect(result?.success).toBe(true);

harness.expectFile(MAIN_OUTPUT).toExist();
harness.expectFile(NAMED_LAZY_OUTPUT).toExist();
harness.expectFile(UNNAMED_LAZY_OUTPUT).toNotExist();
harness.expectFile(NAMED_LAZY_OUTPUT).toNotExist();
harness.expectFile(UNNAMED_LAZY_OUTPUT).toExist();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
beforeEach(async () => {
// Application code is not needed for asset tests
await harness.writeFile('src/main.ts', '');
await harness.writeFile('src/polyfills.ts', '');
});

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

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

harness.useTarget('build', {
...BASE_OPTIONS,
polyfills: 'src/polyfills.ts',
styles: ['src/styles.css'],
});

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

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

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

Expand All @@ -131,6 +137,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
harness.useTarget('build', {
...BASE_OPTIONS,
outputHashing: OutputHashing.All,
sourceMap: true,
styles: [{
input: 'src/styles.css',
inject: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ export const BASE_OPTIONS = Object.freeze<Schema>({
outputPath: 'dist',
tsConfig: 'src/tsconfig.app.json',
progress: false,

// Disable optimizations
optimization: false,
buildOptimizer: false,
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const DEV_SERVER_BUILDER_INFO = Object.freeze({
});

/**
* Contains all required extract-i18n builder fields.
* Contains all required dev-server builder fields.
* The port is also set to zero to ensure a free port is used for each test which
* supports parallel test execution.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { Diagnostics } from '@angular/localize/src/tools/src/diagnostics';
import * as fs from 'fs';
import * as path from 'path';
import * as webpack from 'webpack';
import { Schema as BrowserBuilderOptions } from '../browser/schema';
import { OutputHashing, Schema as BrowserBuilderOptions } from '../browser/schema';
import { ExecutionTransformer } from '../transforms';
import { createI18nOptions } from '../utils/i18n-options';
import { assertCompatibleAngularVersion } from '../utils/version';
Expand Down Expand Up @@ -177,12 +177,15 @@ export async function execute(
buildOptimizer: false,
aot: true,
progress: options.progress,
budgets: [],
assets: [],
scripts: [],
styles: [],
deleteOutputPath: false,
extractLicenses: false,
subresourceIntegrity: false,
outputHashing: OutputHashing.None,
namedChunks: true,
},
context,
(wco) => {
Expand Down
15 changes: 13 additions & 2 deletions packages/angular_devkit/build_angular/src/karma/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { dirname, resolve } from 'path';
import { Observable, from } from 'rxjs';
import { defaultIfEmpty, switchMap } from 'rxjs/operators';
import * as webpack from 'webpack';
import { Schema as BrowserBuilderOptions } from '../browser/schema';
import { OutputHashing, Schema as BrowserBuilderOptions } from '../browser/schema';
import { ExecutionTransformer } from '../transforms';
import { assertCompatibleAngularVersion } from '../utils/version';
import { generateBrowserWebpackConfigFromContext } from '../utils/webpack-browser-config';
Expand Down Expand Up @@ -41,7 +41,18 @@ async function initialize(
// only two properties are missing:
// * `outputPath` which is fixed for tests
// * `budgets` which might be incorrect due to extra dev libs
{ ...((options as unknown) as BrowserBuilderOptions), outputPath: '', budgets: undefined },
{
...((options as unknown) as BrowserBuilderOptions),
outputPath: '',
budgets: undefined,
optimization: false,
buildOptimizer: false,
aot: false,
vendorChunk: true,
namedChunks: true,
extractLicenses: false,
outputHashing: OutputHashing.None,
},
context,
wco => [
getCommonConfig(wco),
Expand Down
6 changes: 3 additions & 3 deletions packages/angular_devkit/build_angular/src/server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"optimization": {
"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.",
"x-user-analytics": 16,
"default": false,
"default": true,
"oneOf": [
{
"type": "object",
Expand Down Expand Up @@ -84,7 +84,7 @@
},
"sourceMap": {
"description": "Output source maps for scripts and styles. For more information, see https://angular.io/guide/workspace-config#source-map-configuration.",
"default": true,
"default": false,
"oneOf": [
{
"type": "object",
Expand Down Expand Up @@ -189,7 +189,7 @@
"namedChunks": {
"type": "boolean",
"description": "Use file name for lazy loaded chunks.",
"default": true
"default": false
},
"bundleDependencies": {
"description": "Which external dependencies to bundle into the bundle. By default, all of node_modules will be bundled.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type NormalizedOptimizationOptions = Required<Omit<OptimizationClass, 'fo
styles: StylesClass,
};

export function normalizeOptimization(optimization: OptimizationUnion = false): NormalizedOptimizationOptions {
export function normalizeOptimization(optimization: OptimizationUnion = true): NormalizedOptimizationOptions {
if (typeof optimization === 'object') {
return {
scripts: !!optimization.scripts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"progress": false,
"sourceMap": true,
"aot": false,
"vendorChunk": true,
"buildOptimizer": false,
"optimization": false,
"extractLicenses": false,
"namedChunks": true,
"assets": [
"src/favicon.ico",
"src/assets"
Expand Down Expand Up @@ -67,7 +74,10 @@
"outputPath": "dist-server",
"main": "src/main.server.ts",
"tsConfig": "src/tsconfig.server.json",
"progress": false
"progress": false,
"sourceMap": true,
"optimization": false,
"extractLicenses": false
}
},
"app-shell": {
Expand Down
12 changes: 5 additions & 7 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
main: `${sourceRoot}/main.ts`,
polyfills: `${sourceRoot}/polyfills.ts`,
tsConfig: `${projectRoot}tsconfig.app.json`,
aot: true,
inlineStyleLanguage,
assets: [
`${sourceRoot}/favicon.ico`,
Expand All @@ -178,16 +177,15 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
replace: `${sourceRoot}/environments/environment.ts`,
with: `${sourceRoot}/environments/environment.prod.ts`,
}],
buildOptimizer: true,
optimization: true,
outputHashing: 'all',
sourceMap: false,
namedChunks: false,
extractLicenses: true,
vendorChunk: false,
},
development: {
buildOptimizer: false,
optimization: false,
vendorChunk: true,
extractLicenses: false,
sourceMap: true,
namedChunks: true,
},
},
},
Expand Down
Loading

0 comments on commit 656f8d7

Please sign in to comment.