-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Conversation
@@ -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}/`); |
There was a problem hiding this comment.
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 }));
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
bdede2b
to
b38438f
Compare
name: 'open', | ||
description: 'Opens the url in default browser', | ||
type: Boolean, | ||
default: false |
There was a problem hiding this comment.
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']
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
This is nice, thanks! I added the request for an alias, I think it would help. People could then do |
b38438f
to
51ffdf0
Compare
} else { | ||
const { open, host, port } = commandOptions; | ||
if (open) { | ||
opn(url.format({ protocol: 'http', hostname: host, port: port.toString() })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
Thank you! |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Sometimes it's really handy to have auto browser opening when serving app.
This PR implements that by
--open
option forng serve
command.Closes #1081