Skip to content
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
3 changes: 2 additions & 1 deletion docs/documentation/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Flag | `--dev` | `--prod`
`--sourcemaps` | `true` | `false`
`--extract-css` | `false` | `true`
`--named-chunks`   | `true` | `false`
`--build-optimizer` | `false` | `true` with AOT and Angular 5

`--extract-licenses` Extract all licenses in a separate file, in the case of production builds only.
`--i18n-file` Localization file to use for i18n.
Expand Down Expand Up @@ -353,7 +354,7 @@ Note: service worker support is experimental and subject to change.
<code>--build-optimizer</code>
</p>
<p>
(Experimental) Enables @angular-devkit/build-optimizer optimizations when using `--aot`.
Enables @angular-devkit/build-optimizer optimizations when using `--aot`.
</p>
</details>

Expand Down
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"enhanced-resolve": "^3.4.1",
"exports-loader": "^0.6.3",
"extract-text-webpack-plugin": "3.0.0",
"file-loader": "^0.10.0",
"file-loader": "^1.1.5",
"fs-extra": "^4.0.0",
"glob": "^7.0.3",
"html-webpack-plugin": "^2.29.0",
Expand Down Expand Up @@ -92,12 +92,13 @@
"tree-kill": "^1.0.0",
"typescript": "~2.4.2",
"uglifyjs-webpack-plugin": "1.0.0-beta.1",
"url-loader": "^0.6.0",
"url-loader": "^0.6.2",
"webpack": "~3.7.1",
"webpack-concat-plugin": "1.4.0",
"webpack-dev-middleware": "~1.12.0",
"webpack-dev-server": "~2.7.1",
"webpack-merge": "^4.1.0",
"webpack-sources": "^1.0.0",
"webpack-subresource-integrity": "^1.0.1",
"zone.js": "^0.8.14"
},
Expand Down
4 changes: 1 addition & 3 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ export const baseBuildCommandOptions: any = [
{
name: 'build-optimizer',
type: Boolean,
default: false,
description: '(Experimental) Enables @angular-devkit/build-optimizer '
+ 'optimizations when using `--aot`.'
description: 'Enables @angular-devkit/build-optimizer optimizations when using `--aot`.'
},
{
name: 'named-chunks',
Expand Down
13 changes: 11 additions & 2 deletions packages/@angular/cli/models/webpack-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AngularCompilerPlugin } from '@ngtools/webpack';
import { readTsconfig } from '../utilities/read-tsconfig';
const webpackMerge = require('webpack-merge');
import { CliConfig } from './config';
Expand Down Expand Up @@ -94,7 +95,8 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
sourcemaps: true,
extractCss: false,
namedChunks: true,
aot: false
aot: false,
buildOptimizer: false
},
production: {
environment: 'prod',
Expand All @@ -106,7 +108,14 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
}
};

return Object.assign({}, targetDefaults[buildOptions.target], buildOptions);
const merged = Object.assign({}, targetDefaults[buildOptions.target], buildOptions);

// Use Build Optimizer on prod AOT builds by default when AngularCompilerPlugin is supported.
const buildOptimizer = {
buildOptimizer: merged.aot && AngularCompilerPlugin.isSupported()
};

return Object.assign({}, buildOptimizer, merged);
}

// Fill in defaults from .angular-cli.json
Expand Down
15 changes: 13 additions & 2 deletions packages/@angular/cli/models/webpack-configs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,21 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
module: {
rules: [
{ test: /\.html$/, loader: 'raw-loader' },
{ test: /\.(eot|svg|cur)$/, loader: `file-loader?name=[name]${hashFormat.file}.[ext]` },
{
test: /\.(eot|svg|cur)$/,
loader: 'file-loader',
options: {
name: `[name]${hashFormat.file}.[ext]`,
limit: 10000
}
},
{
test: /\.(jpg|png|webp|gif|otf|ttf|woff|woff2|ani)$/,
loader: `url-loader?name=[name]${hashFormat.file}.[ext]&limit=10000`
loader: 'url-loader',
options: {
name: `[name]${hashFormat.file}`,
limit: 10000
}
}
].concat(extraRules)
},
Expand Down
7 changes: 7 additions & 0 deletions packages/@angular/cli/models/webpack-configs/production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import { readTsconfig } from '../../utilities/read-tsconfig';

const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

/**
* license-webpack-plugin has a peer dependency on webpack-sources, list it in a comment to
* let the dependency validator know it is used.
*
* require('webpack-sources')
*/


export function getProdConfig(wco: WebpackConfigOptions) {
const { projectRoot, buildOptions, appConfig } = wco;
Expand Down
5 changes: 3 additions & 2 deletions packages/@angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"ember-cli-string-utils": "^1.0.0",
"exports-loader": "^0.6.3",
"extract-text-webpack-plugin": "3.0.0",
"file-loader": "^0.10.0",
"file-loader": "^1.1.5",
"fs-extra": "^4.0.0",
"glob": "^7.0.3",
"html-webpack-plugin": "^2.29.0",
Expand Down Expand Up @@ -75,12 +75,13 @@
"stylus-loader": "^3.0.1",
"typescript": ">=2.0.0 <2.6.0",
"uglifyjs-webpack-plugin": "1.0.0-beta.1",
"url-loader": "^0.6.0",
"url-loader": "^0.6.2",
"webpack": "~3.7.1",
"webpack-concat-plugin": "1.4.0",
"webpack-dev-middleware": "~1.12.0",
"webpack-dev-server": "~2.7.1",
"webpack-merge": "^4.1.0",
"webpack-sources": "^1.0.0",
"webpack-subresource-integrity": "^1.0.1",
"zone.js": "^0.8.14"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/upgrade/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class Version {
const versionCombos = [
{ compiler: '>=2.3.1 <3.0.0', typescript: '>=2.0.2 <2.3.0' },
{ compiler: '>=4.0.0 <5.0.0', typescript: '>=2.1.0 <2.4.0' },
{ compiler: '>=5.0.0 <6.0.0', typescript: '>=2.4.0 <2.6.0' }
{ compiler: '>=5.0.0 <6.0.0', typescript: '>=2.4.0 <2.5.0' }
];

const currentCombo = versionCombos.find((combo) => satisfies(compilerVersion, combo.compiler));
Expand Down
32 changes: 27 additions & 5 deletions packages/@ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs';
import { fork, ChildProcess } from 'child_process';
import { fork, ForkOptions, ChildProcess } from 'child_process';
import * as path from 'path';
import * as ts from 'typescript';

Expand Down Expand Up @@ -458,7 +458,29 @@ export class AngularCompilerPlugin implements Tapable {
? './type_checker_bootstrap.js'
: './type_checker.js';

this._typeCheckerProcess = fork(path.resolve(__dirname, typeCheckerFile));
let hasMemoryFlag = false;
const memoryFlagRegex = /--max-old-space-size/;
const debugArgRegex = /--inspect(?:-brk|-port)?|--debug(?:-brk|-port)/;

const execArgv = process.execArgv.filter((arg) => {
// Check if memory is being set by parent process.
if (memoryFlagRegex.test(arg)) {
hasMemoryFlag = true;
}

// Remove debug args.
// Workaround for https://github.com/nodejs/node/issues/9435
return !debugArgRegex.test(arg);
});

if (!hasMemoryFlag) {
// Force max 8gb ram.
execArgv.push('--max-old-space-size=8192');
}

const forkOptions: ForkOptions = { execArgv };

this._typeCheckerProcess = fork(path.resolve(__dirname, typeCheckerFile), [], forkOptions);
this._typeCheckerProcess.send(new InitMessage(this._compilerOptions, this._basePath,
this._JitMode, this._tsFilenames));

Expand All @@ -467,9 +489,9 @@ export class AngularCompilerPlugin implements Tapable {
treeKill(this._typeCheckerProcess.pid, 'SIGTERM');
process.exit();
};
process.on('exit', killTypeCheckerProcess);
process.on('SIGINT', killTypeCheckerProcess);
process.on('uncaughtException', killTypeCheckerProcess);
process.once('exit', killTypeCheckerProcess);
process.once('SIGINT', killTypeCheckerProcess);
process.once('uncaughtException', killTypeCheckerProcess);
}

private _updateForkedTypeChecker(changedTsFiles: string[]) {
Expand Down
1 change: 0 additions & 1 deletion packages/@ngtools/webpack/src/type_checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class TypeChecker {
options: this._angularCompilerOptions,
tsHost: compilerHost
}) as CompilerHost & WebpackCompilerHost;
this._tsFilenames = [];
timeEnd('TypeChecker.constructor');
}

Expand Down
8 changes: 7 additions & 1 deletion tests/e2e/tests/build/aot/angular-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ng, silentNpm } from '../../../utils/process';
import { updateJsonFile } from '../../../utils/project';
import { expectFileToMatch, rimraf, moveFile } from '../../../utils/fs';
import { expectFileToMatch, rimraf, moveFile, expectFileToExist } from '../../../utils/fs';
import { getGlobalVariable } from '../../../utils/env';
import { expectToFail } from '../../../utils/utils';

Expand All @@ -13,6 +13,7 @@ export default function () {
return Promise.resolve();
}

// These tests should be moved to the default when we use ng5 in new projects.
return Promise.resolve()
.then(() => moveFile('node_modules', '../node_modules'))
.then(() => updateJsonFile('package.json', packageJson => {
Expand All @@ -36,6 +37,11 @@ export default function () {
.then(() => expectFileToMatch('dist/main.bundle.js',
/bootstrapModuleFactory.*\/\* AppModuleNgFactory \*\//))

// Build optimizer should default to true on prod builds.
.then(() => ng('build', '--prod', '--output-hashing=none'))
.then(() => expectToFail(() => expectFileToExist('dist/vendor.js')))
.then(() => expectToFail(() => expectFileToMatch('dist/main.js', /\.decorators =/)))

// tests for register_locale_data transformer
.then(() => rimraf('dist'))
.then(() => ng('build', '--locale=fr'))
Expand Down