Skip to content

Commit 8ef986b

Browse files
committed
feat(@angular/cli): add eject command
1 parent 8e69b3b commit 8ef986b

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

docs/documentation/eject.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@
33
# ng eject
44

55
## Overview
6-
Temporarily disabled. Ejects your app and output the proper webpack configuration and scripts.
6+
Create a basic Webpack configuration for your app.
7+
8+
This command will create a basic webpack configuration and update your `angular.json` file to use it.
9+
10+
This configuration will include the necessary plugins and loader to build Angular applications.
11+
You may need to edit this configuration to match more advanced build options that your project was using.
12+
13+
You can then build using this configuration via `ng run project-name:build-webpack`.
14+
15+
To build for production use `ng run project-name:build-webpack:production` instead.
16+
17+
To serve using Webpack Dev Server, use `ng run project-name:serve-webpack`.
718

819
## Options
920
None.
Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
1-
import { tags } from '@angular-devkit/core';
2-
import { Command, Option } from '../models/command';
1+
import { CommandScope, Option } from '../models/command';
2+
import { CoreSchematicOptions, SchematicCommand } from '../models/schematic-command';
33

44

5-
export default class EjectCommand extends Command {
5+
export interface EjectOptions extends CoreSchematicOptions { }
6+
7+
export default class EjectCommand extends SchematicCommand {
68
public readonly name = 'eject';
7-
public readonly description = 'Temporarily disabled. Ejects your app and output the proper '
8-
+ 'webpack configuration and scripts.';
9-
public readonly arguments: string[] = [];
10-
public readonly options: Option[] = [];
9+
public readonly description = 'Create a basic Webpack configuration for your app.';
10+
public static aliases: string[] = [];
11+
public readonly scope = CommandScope.everywhere;
12+
public arguments: string[] = [];
13+
public options: Option[] = [];
14+
15+
private collectionName = '@schematics/angular';
16+
private schematicName = 'update';
1117

12-
run() {
13-
this.logger.info(tags.stripIndents`
14-
The 'eject' command has been temporarily disabled, as it is not yet compatible with the new
15-
angular.json format. The new configuration format provides further flexibility to modify the
16-
configuration of your workspace without ejecting. Ejection will be re-enabled in a future
17-
release of the CLI.
18+
private initialized = false;
19+
public async initialize(options: any) {
20+
if (this.initialized) {
21+
return;
22+
}
23+
super.initialize(options);
24+
this.initialized = true;
25+
26+
const schematicOptions = await this.getOptions({
27+
schematicName: this.schematicName,
28+
collectionName: this.collectionName,
29+
});
30+
this.options = this.options.concat(schematicOptions.options);
31+
this.arguments = this.arguments.concat(schematicOptions.arguments.map(a => a.name));
32+
}
1833

19-
If you need to eject today, use CLI 1.7 to eject your project.
20-
`);
34+
public async run(options: EjectOptions) {
35+
return this.runSchematic({
36+
collectionName: this.collectionName,
37+
schematicName: this.schematicName,
38+
schematicOptions: options,
39+
dryRun: options.dryRun,
40+
force: false,
41+
showNothingDone: false,
42+
});
2143
}
2244
}

packages/@angular/cli/lib/cli/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function loadCommands() {
1111
'new': require('../../commands/new').default,
1212
'generate': require('../../commands/generate').default,
1313
'update': require('../../commands/update').default,
14+
'eject': require('../../commands/eject').default,
1415

1516
// Architect commands.
1617
'build': require('../../commands/build').default,
@@ -21,9 +22,6 @@ function loadCommands() {
2122
'xi18n': require('../../commands/xi18n').default,
2223
'run': require('../../commands/run').default,
2324

24-
// Disabled commands.
25-
'eject': require('../../commands/eject').default,
26-
2725
// Easter eggs.
2826
'make-this-awesome': require('../../commands/easter-egg').default,
2927

0 commit comments

Comments
 (0)