Skip to content

Commit f29c264

Browse files
committed
feat(serve): implement open browser option
Closes angular#1081
1 parent 911caa2 commit f29c264

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/angular-cli/commands/serve.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface ServeTaskOptions {
2626
sslKey?: string;
2727
sslCert?: string;
2828
aot?: boolean;
29+
open?: boolean;
2930
}
3031

3132
const ServeCommand = Command.extend({
@@ -79,7 +80,13 @@ const ServeCommand = Command.extend({
7980
{ name: 'ssl', type: Boolean, default: false },
8081
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
8182
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' },
82-
{ name: 'aot', type: Boolean, default: false }
83+
{ name: 'aot', type: Boolean, default: false },
84+
{
85+
name: 'open',
86+
description: 'Opens the url in default browser',
87+
type: Boolean,
88+
default: false
89+
},
8390
],
8491

8592
run: function(commandOptions: ServeTaskOptions) {

packages/angular-cli/tasks/serve-webpack.ts

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { NgCliWebpackConfig } from '../models/webpack-config';
1111
import { ServeTaskOptions } from '../commands/serve';
1212
import { CliConfig } from '../models/config';
1313
import { oneLine } from 'common-tags';
14+
const opn = require('opn');
1415

1516
export default Task.extend({
1617
run: function(commandOptions: ServeTaskOptions) {
@@ -78,6 +79,10 @@ export default Task.extend({
7879
console.error(err.stack || err);
7980
if (err.details) { console.error(err.details); }
8081
reject(err.details);
82+
} else {
83+
if(commandOptions.open) {
84+
opn(`http://${commandOptions.host}:${commandOptions.port}/`);
85+
}
8186
}
8287
});
8388
});

0 commit comments

Comments
 (0)