Skip to content

feat(@angular/cli): use architect #9883

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 2 commits into from
Mar 16, 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
1,185 changes: 799 additions & 386 deletions package-lock.json

Large diffs are not rendered by default.

43 changes: 3 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,63 +41,29 @@
},
"homepage": "https://github.com/angular/angular-cli",
"dependencies": {
"@angular-devkit/build-optimizer": "0.4.5",
"@angular-devkit/core": "0.4.5",
"@angular-devkit/architect": "angular/angular-devkit-architect-builds#891f470",
"@angular-devkit/build-webpack": "angular/angular-devkit-build-webpack-builds#891f470",
"@angular-devkit/core": "angular/angular-devkit-core-builds#891f470",
"@angular-devkit/schematics": "0.4.5",
"@schematics/angular": "0.4.5",
"@schematics/package-update": "0.4.5",
"ajv": "^6.1.1",
"autoprefixer": "^7.2.3",
"cache-loader": "^1.2.0",
"chalk": "~2.2.0",
"circular-dependency-plugin": "^4.4.0",
"clean-css": "^4.1.9",
"common-tags": "^1.3.1",
"copy-webpack-plugin": "~4.4.2",
"core-object": "^3.1.0",
"ember-cli-string-utils": "^1.0.0",
"extract-text-webpack-plugin": "~4.0.0-beta.0",
"file-loader": "^1.1.9",
"fs-extra": "^4.0.0",
"glob": "^7.0.3",
"html-webpack-plugin": "github:webpack-contrib/html-webpack-plugin#a8a8c2b6ea496c257fd6f501db3a06a51fa03e1e",
"istanbul-instrumenter-loader": "^3.0.0",
"karma-source-map-support": "^1.2.0",
"less": "^2.7.2",
"less-loader": "^4.0.5",
"license-webpack-plugin": "^1.1.2",
"loader-utils": "^1.1.0",
"lodash": "^4.11.1",
"memory-fs": "^0.4.1",
"minimatch": "^3.0.4",
"node-modules-path": "^1.0.0",
"opn": "~5.1.0",
"parse5": "^4.0.0",
"portfinder": "~1.0.12",
"postcss": "^6.0.19",
"postcss-import": "^11.1.0",
"postcss-loader": "^2.1.1",
"postcss-url": "^7.1.2",
"raw-loader": "^0.5.1",
"resolve": "^1.1.7",
"rxjs": "^5.5.6",
"sass-loader": "^6.0.6",
"semver": "^5.3.0",
"silent-error": "^1.0.0",
"source-map-support": "^0.4.1",
"style-loader": "^0.20.2",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"tree-kill": "^1.0.0",
"typescript": "~2.6.2",
"uglifyjs-webpack-plugin": "^1.2.2",
"url-loader": "^0.6.2",
"webpack": "~4.0.0",
"webpack-dev-middleware": "^2.0.6",
"webpack-dev-server": "^3.0.1-beta.0",
"webpack-merge": "^4.1.2",
"webpack-sources": "^1.1.0",
"webpack-subresource-integrity": "^1.0.1",
"yargs-parser": "^9.0.2"
},
"devDependencies": {
Expand Down Expand Up @@ -142,8 +108,5 @@
"ts-node": "^4.1.0",
"tslint": "^5.8.0",
"zone.js": "^0.8.20"
},
"optionalDependencies": {
"node-sass": "^4.7.2"
}
}
299 changes: 25 additions & 274 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,293 +1,44 @@
import { Command, Option, CommandScope } from '../models/command';
import { CliConfig } from '../models/config';
import { BuildOptions } from '../models/build-options';
import { ArchitectCommand } from '../models/architect-command';
import { Option, CommandScope } from '../models/command';
import { Version } from '../upgrade/version';
import { oneLine } from 'common-tags';
import { getAppFromConfig } from '../utilities/app-utils';
import { join } from 'path';
import { RenderUniversalTaskOptions } from '../tasks/render-universal';

const SilentError = require('silent-error');

const config = CliConfig.fromProject() || CliConfig.fromGlobal();
const buildConfigDefaults = config.getPaths('defaults.build', [
'sourcemaps', 'baseHref', 'progress', 'poll', 'deleteOutputPath', 'preserveSymlinks',
'showCircularDependencies', 'commonChunk', 'namedChunks'
]);

// defaults for BuildOptions
export const baseBuildCommandOptions: Option[] = [
{
name: 'target',
type: String,
default: 'development',
// TODO: re-add support for `--prod`
aliases: ['t'],
description: 'Defines the build target.'
},
{
name: 'environment',
type: String,
aliases: ['e'],
description: 'Defines the build environment.'
},
{
name: 'output-path',
type: 'Path',
aliases: ['op'],
description: 'Path where output will be placed.'
},
{
name: 'aot',
type: Boolean,
description: 'Build using Ahead of Time compilation.'
},
{
name: 'sourcemaps',
type: Boolean,
aliases: ['sm', 'sourcemap'],
description: 'Output sourcemaps.',
default: buildConfigDefaults['sourcemaps']
},
{
name: 'vendor-chunk',
type: Boolean,
aliases: ['vc'],
description: 'Use a separate bundle containing only vendor libraries.'
},
{
name: 'common-chunk',
type: Boolean,
default: buildConfigDefaults['commonChunk'],
aliases: ['cc'],
description: 'Use a separate bundle containing code used across multiple bundles.'
},
{
name: 'base-href',
type: String,
aliases: ['bh'],
description: 'Base url for the application being built.',
default: buildConfigDefaults['baseHref']
},
{
name: 'deploy-url',
type: String,
aliases: ['d'],
description: 'URL where files will be deployed.'
},
{
name: 'verbose',
type: Boolean,
default: false,
aliases: ['v'],
description: 'Adds more details to output logging.'
},
{
name: 'progress',
type: Boolean,
aliases: ['pr'],
description: 'Log progress to the console while building.',
default: typeof buildConfigDefaults['progress'] !== 'undefined'
? buildConfigDefaults['progress']
: process.stdout.isTTY === true
},
{
name: 'i18n-file',
type: String,
description: 'Localization file to use for i18n.'
},
{
name: 'i18n-format',
type: String,
description: 'Format of the localization file specified with --i18n-file.'
},
{
name: 'locale',
type: String,
description: 'Locale to use for i18n.'
},
{
name: 'missing-translation',
type: String,
description: 'How to handle missing translations for i18n.'
},
{
name: 'extract-css',
type: Boolean,
aliases: ['ec'],
description: 'Extract css from global styles onto css files instead of js ones.'
},
{
name: 'watch',
type: Boolean,
default: false,
aliases: ['w'],
description: 'Run build when files change.'
},
{
name: 'output-hashing',
type: String,
values: ['none', 'all', 'media', 'bundles'],
description: 'Define the output filename cache-busting hashing mode.',
aliases: ['oh']
},
{
name: 'poll',
type: Number,
description: 'Enable and define the file watching poll time period (milliseconds).',
default: buildConfigDefaults['poll']
},
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name or index to use.'
},
{
name: 'delete-output-path',
type: Boolean,
aliases: ['dop'],
description: 'Delete output path before build.',
default: buildConfigDefaults['deleteOutputPath'],
},
{
name: 'preserve-symlinks',
type: Boolean,
description: 'Do not use the real path when resolving modules.',
default: buildConfigDefaults['preserveSymlinks']
},
{
name: 'extract-licenses',
type: Boolean,
description: 'Extract all licenses in a separate file, in the case of production builds only.'
},
{
name: 'show-circular-dependencies',
type: Boolean,
aliases: ['scd'],
description: 'Show circular dependency warnings on builds.',
default: buildConfigDefaults['showCircularDependencies']
},
{
name: 'build-optimizer',
type: Boolean,
description: 'Enables @angular-devkit/build-optimizer optimizations when using `--aot`.'
},
{
name: 'named-chunks',
type: Boolean,
aliases: ['nc'],
description: 'Use file name for lazy loaded chunks.',
default: buildConfigDefaults['namedChunks']
},
{
name: 'subresource-integrity',
type: Boolean,
default: false,
aliases: ['sri'],
description: 'Enables the use of subresource integrity validation.'
},
{
name: 'bundle-dependencies',
type: ['none', 'all'],
default: 'none',
description: 'Available on server platform only. Which external dependencies to bundle into '
+ 'the module. By default, all of node_modules will be kept as requires.'
},
{
name: 'service-worker',
type: Boolean,
default: true,
aliases: ['sw'],
description: 'Generates a service worker config for production builds, if the app has '
+ 'service worker enabled.'
},
{
name: 'skip-app-shell',
type: Boolean,
description: 'Flag to prevent building an app shell',
default: false
}
];

export interface BuildTaskOptions extends BuildOptions {
statsJson?: boolean;
export interface Options {
app?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

project?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to be changed this week, but can be after this PR.

configuration?: string;
prod: boolean;
}

export default class BuildCommand extends Command {
export default class BuildCommand extends ArchitectCommand {
public readonly name = 'build';
public readonly target = 'browser';
public readonly description =
'Builds your app and places it into the output path (dist/ by default).';
public static aliases = ['b'];
public scope = CommandScope.inProject;
public arguments: string[];
public options = baseBuildCommandOptions.concat([
{
name: 'stats-json',
type: Boolean,
default: false,
description: oneLine`Generates a \`stats.json\` file which can be analyzed using tools
such as: \`webpack-bundle-analyzer\` or https://webpack.github.io/analyse.`
}
]);
public arguments: string[] = ['app'];
public options: Option[] = [
this.prodOption,
this.configurationOption
];

public validate(_options: BuildTaskOptions) {
public validate(_options: Options) {
Version.assertAngularVersionIs2_3_1OrHigher(this.project.root);
Version.assertTypescriptVersion(this.project.root);
return true;
}

public async run(options: BuildTaskOptions) {
// Add trailing slash if missing to prevent https://github.com/angular/angular-cli/issues/7295
if (options.deployUrl && options.deployUrl.substr(-1) !== '/') {
options.deployUrl += '/';
}

const BuildTask = require('../tasks/build').default;

const buildTask = new BuildTask({
project: this.project,
ui: this.ui,
});

const clientApp = getAppFromConfig(options.app);

const doAppShell = options.target === 'production' &&
(options.aot === undefined || options.aot === true) &&
!options.skipAppShell;

let serverApp: any = null;
if (clientApp.appShell && doAppShell) {
serverApp = getAppFromConfig(clientApp.appShell.app);
if (serverApp.platform !== 'server') {
throw new SilentError(`Shell app's platform is not "server"`);
}
}

const buildTaskResult = await buildTask.run(options);
if (!clientApp.appShell || !doAppShell) {
return buildTaskResult;
public async run(options: Options) {
let configuration = options.configuration;
if (!configuration && options.prod) {
configuration = 'production';
}

const serverOptions = {
...options,
app: clientApp.appShell.app
};
await buildTask.run(serverOptions);

const RenderUniversalTask = require('../tasks/render-universal').default;

const renderUniversalTask = new RenderUniversalTask({
project: this.project,
ui: this.ui,
const overrides = {...options};
delete overrides.app;
delete overrides.prod;
return this.runArchitect({
app: options.app,
configuration,
overrides
});
const renderUniversalOptions: RenderUniversalTaskOptions = {
inputIndexPath: join(this.project.root, clientApp.outDir, clientApp.index),
route: clientApp.appShell.route,
serverOutDir: join(this.project.root, serverApp.outDir),
outputIndexPath: join(this.project.root, clientApp.outDir, clientApp.index)
};

return await renderUniversalTask.run(renderUniversalOptions);
}
}
Loading