Skip to content
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

feat(serve): implement open default browser option for ng serve #2489

Closed
wants to merge 2 commits into from

Conversation

dzonatan
Copy link
Contributor

@dzonatan dzonatan commented Oct 3, 2016

Sometimes it's really handy to have auto browser opening when serving app.
This PR implements that by --open option for ng serve command.

Closes #1081

@@ -78,6 +79,10 @@ export default Task.extend({
console.error(err.stack || err);
if (err.details) { console.error(err.details); }
reject(err.details);
} else {
if(commandOptions.open) {
opn(`http://${commandOptions.host}:${commandOptions.port}/`);
Copy link

@graingert graingert Oct 6, 2016

Choose a reason for hiding this comment

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

import url from 'url';
...
const { open, host, port } = commandOptions;
if (open) {
  opn(url.format({ protocol: 'http', hostname: host, port }));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are there any pros of that url formatter?
I was trying to make it same as webpack dev server binary do.

Choose a reason for hiding this comment

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

It's built in and escapes funky stuff like ipv6 addresses properly

@dzonatan dzonatan force-pushed the default-browser-opening branch 2 times, most recently from bdede2b to b38438f Compare October 7, 2016 18:54
name: 'open',
description: 'Opens the url in default browser',
type: Boolean,
default: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add the o alias?

aliases: ['o']

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@filipesilva
Copy link
Contributor

This is nice, thanks! I added the request for an alias, I think it would help. People could then do ng serve -o.

} else {
const { open, host, port } = commandOptions;
if (open) {
opn(url.format({ protocol: 'http', hostname: host, port: port.toString() }));

Choose a reason for hiding this comment

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

nice

@Splaktar
Copy link
Member

Thank you!

@dzonatan dzonatan deleted the default-browser-opening branch October 11, 2016 06:34
JJayet pushed a commit to JJayet/angular-cli that referenced this pull request Oct 14, 2016
Brocco pushed a commit that referenced this pull request Oct 19, 2016
texel pushed a commit to splice/angular-cli that referenced this pull request Nov 3, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Executing "ng serve" or "npm start" command browser is not opening automatically
5 participants