Angular-cli: Launch site after ng serve?

Created on 29 Jun 2016  路  8Comments  路  Source: angular/angular-cli

Is it possible to have ng serve launch your site after it starts up? I find this easier than having to copy the localhost with port address from the terminal and paste it into a new browser tab

Most helpful comment

This could be pretty easy to implement. I've done this before with the OPN package https://www.npmjs.com/package/opn.

There could be an additional flag on the serve command similar to the ones below:

  • ng serve --browser to open the default browser
  • ng serve --browser=firefox to open a specific browser

If anyone else thinks this is a good idea I may try a pull-request at this one.

All 8 comments

This could be pretty easy to implement. I've done this before with the OPN package https://www.npmjs.com/package/opn.

There could be an additional flag on the serve command similar to the ones below:

  • ng serve --browser to open the default browser
  • ng serve --browser=firefox to open a specific browser

If anyone else thinks this is a good idea I may try a pull-request at this one.

Being able to select a browser like you suggested would be a nice touch as well.

Please feel free to continue the discussion and proposals in the other issue though!

@austin94 do you mind show how you implement OPN?

@keepscoding This conversation should probably be moved to the duplicate issue if that's still active, but from opn README https://www.npmjs.com/package/opn (or you can use the opn-cli package) we could just grab the port that it was started on and add the app name based off of a argument passed in.

// specify the app to open in 
opn('http://localhost:3000', {app: 'firefox'});
opn('http://localhost:3000', {app: 'google chrome'});

// for default browser
opn('http://localhost:3000');

@austin94 where to add these code e.g. open default browser?

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._

Was this page helpful?
0 / 5 - 0 ratings